Joe
Joe

Reputation: 1635

Using if statement inside for loop - Javascript

I have a Javascript For Loop...

var CookieName = "Tab,EduTab,EduTab,user";
var tString = CookieName.split(',');

for(i = 0; i < tString.length; i++){

    if (tString[i] == "EduTab") {
        document.write("<b>"+tString[i]+"<b>"); 
    } else {
        document.write(tString[i]);
    }
}

For some reason it is failing to bold the 'EduTab'. It will either bold the entire array CookieName or none at all. Any help would be awesome. Thanks.

Upvotes: 3

Views: 12430

Answers (2)

Nettogrof
Nettogrof

Reputation: 2136

You are missing the / in your closing tab </b>

Upvotes: 7

nwellcome
nwellcome

Reputation: 2299

You aren't closing the <b> tag

document.write("<b>"+tString[i]+"<b>")

should be

document.write("<b>"+tString[i]+"</b>")

Upvotes: 7

Related Questions