Append link to head javascript

What I am trying to accomplish is use javascript to write a element in the section. The link element that i'm trying to add looks like this

As requested I've posted the entire code.:




    Extra-Life Alerts
    
    

    
        var effect = $.url[].param['effect'];
        var font = $.url[].param['font'];
        /*
         //document.getElementById["body"].innerHTML = document.write[''];
         //document.getElementById['head'].innerHTML += '';
         //var stylesheetAdd = '';

         $[function[] {
         $['head'].append[''];
         }];

         //var headID = document.getElementsByTagName["head"][0];
         //$[headID].append[''];
         //document.getElementById['#posts'].className = 'font-effect-' + effect;
         //document.getElementById['#posts'].style.fontFamily = font;
         //$["#posts"].className["font-effect-" + effect].style.fontFamily[font]; //= 'font-effect-' + effect;
         //$["#posts"].style.fontFamily[font]; //= font;
         //if [font] { $['.wf-active body, .wf-inactive body, #posts, body'].css['font-family', font]; }
         //else{font="Impact"; $['.wf-active body, .wf-inactive body, #posts, body'].css['font-family', font];}
         */
        /*
        //$['head'].append[''];
        var stylesheetAdd = '';
        //$['head'].append[''];
        $[stylesheetAdd].appendTo[document.head];
        */

        var headID = document.getElementsByTagName['head'][0];
        var link = document.createElement['link'];
        link.type = 'text/css';
        link.rel = 'stylesheet';
        link.href = '//fonts.googleapis.com/css?family=Oswald&effect=neon';
        headID.appendChild[link];

        /*
        var link = $['']
            .appendTo[document.getElementsByTagName['head'][0]]
            .attr['rel', "stylesheet"]
            .attr['type', "text/css"]
            .attr['href', "//fonts.googleapis.com/css?family=Oswald&effect=neon"];
        $[function[]{
           $[link];
        }];
        */
    

    








    var checkPriorDonorName = "prior name";
    var getCurrentDonorName = "current name";
    var checkPriorMessage = "prior message";
    var getCurrentMessage = "current message";

    function init[] {

        // Parse setup parameters.
        var id = $.url[].param['id'];
        var audio = $.url[].param['audio'];
        var playAudio = document.createElement["AUDIO"];

        var xmlhttp = new XMLHttpRequest[];
        //var url = "//2dc8c656ef.test-url.ws/tempDonations.txt";
        var url = "//www.extra-life.org/index.cfm?fuseaction=donorDrive.participantDonations&participantID=" + id + "&format=json";
        xmlhttp.open["GET", url, true];
        xmlhttp.send[];

        xmlhttp.onreadystatechange = function [] {
            getCurrentDonorName = xmlhttp.responseText;
            getCurrentMessage = xmlhttp.responseText
        };
        getCurrentDonorName = JSON.parse[getCurrentDonorName];
        getCurrentMessage = JSON.parse[getCurrentMessage];

        xmlhttp.onreadystatechange = function [] {
            if [[xmlhttp.readyState == '4' && [ xmlhttp.status == '200' || xmlhttp.status == '204' ]] &&
                    [ checkPriorDonorName === "prior name" || getCurrentDonorName[0].donorName != checkPriorDonorName ] &&
                    [ checkPriorMessage === "prior message"] || getCurrentMessage[0].message != checkPriorMessage] {
                extraLifeAlert[xmlhttp.responseText];
            }
            else
                return;
        };

        /** Debugging steps
         console.log["TEST BEGINNING NAME:   Current: " + getCurrentDonorName[0].donorName + " | Prior: " + checkPriorDonorName];
         console.log["TEST BEGINNING MESSAGE:   Current: " + getCurrentMessage[0].message + " | Prior: " + checkPriorMessage];
         */

        function extraLifeAlert[response] {
            var donorName = JSON.parse[response];
            var message = JSON.parse[response];
            var donationAmount = JSON.parse[response];

            if [donorName[0].donorName] {
                $['#posts'].find['.donorName'].text[donorName[0].donorName];
            }
            if [donationAmount[0].donationAmount] {
                $['#posts'].find['.donationAmount'].text[donationAmount[0].donationAmount];
            }
            if [message[0].message !== null] {
                $['#posts'].find['.message'].text[message[0].message];
            }
            else {
                $["#posts"].find[".message"].text[""];
            }

            //setTimeout[function[]{document.getElementById['#posts'].attr['style', 'display: none']}, 0];
            //setTimeout[function[]{document.getElementById['#posts'].attr['style', 'display: inline']}, 2000];
            setTimeout[function [] {
                document.getElementById['#posts'].style.display = 'none'
            }, 0];
            setTimeout[function [] {
                document.getElementById['#posts'].style.display = 'inline'
            }, 2000];
            if [audio] {
                playAudio.setAttribute["src", audio];
                playAudio.load[];
                playAudio.play[];
            }
            setTimeout[function [] {
                $["#posts"].fadeIn[1000];
            }, 1000];
            setTimeout[function [] {
                $["#posts"].fadeOut[1000];
            }, 10000];

            checkPriorDonorName = donorName[0].donorName;
            checkPriorMessage = message[0].message;
        }
    }
    /** Debugging steps
     console.log["TEST END NAME:   Current: " + getCurrentDonorName[0].donorName + " | Prior: " + checkPriorDonorName];
     console.log["TEST END MESSAGE:   Current: " + getCurrentMessage[0].message + " | Prior: " + checkPriorMessage];
     */
    setInterval[init, 5000];


 Just donated $.00 - 

Opps think i cut and pasted out some stuff. So the only think that matters to get this google font+effects to work is that 1]you add the tag in the , 2]add the font & effect class in the section where your text is. For right now i'm manually entered it in for testing purposes. I plan to control all this via script so that the user can put the options in the url and have it work.

How do you append a link in JavaScript?

Approach:.
Create an anchor element..
Create a text node with some text which will display as a link..
Append the text node to the anchor element..
Set the title and href property of the element..
Append element in the body..

How do you link a JavaScript head?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the tags in your HTML document.

Does link go in head?

The tag in HTML is used to define a link between a document and an external resource. The link tag is mainly used to link to external style sheets. This element can appear multiple times but it goes only in the head section.

What is insert element into document head in JavaScript?

The content to be added can be first created using the createElement[] method and the required properties can be assigned to it. The appendChild[] method appends this created element to the head of the document.

Chủ Đề