Diego
Diego

Reputation: 964

Add inline style using Javascript to divs created dynamically

I'm creating dynamically divs using javascript. I want to assign the style to none.

style="display: none;"

According to this question, I can to do this with the following options

 publishcontent.style.display="none";
 publishcontent.setAttribute("style", "display: none;");

But this isn't working. This is the way I created the divs. No way of the options I found is working. If I edit the html with firebug and type style="display: none;" it works.

This is a demo showing the example.

publishpaging=document.createElement("div");
var name="df"+counterName;
publishpaging.id=name;
counterName=counterName+1;
arrayNames.push(name);
counter++;
publishcontent=document.createElement("div");//"<div class='bonecardSmall'></div>";
publishcontent.className = "bonecardSmallP";
publishcontent.id=index.id;
if(arrayNames.length > 1){
    //publishpaging.style.display="none";
    publishpaging.setAttribute("style", "display: none;");
}
publishpaging.appendChild(publishcontent);

Upvotes: 1

Views: 2779

Answers (4)

gaurav
gaurav

Reputation: 230

you can simply hide using jquery hide function.

$("#"+ name).hide();

Upvotes: 0

user3459464
user3459464

Reputation: 224

"name" variable stores the id of publishcontent so use it in jquery

 $('#'+name).css('display','none');

Upvotes: 5

user3136030
user3136030

Reputation: 384

Using jquery try this,

$('yourdivtagid').css('display','none')

Upvotes: 0

Amin Jafari
Amin Jafari

Reputation: 7207

using jQuery, just use:

$('div').css('display','none');

Upvotes: 0

Related Questions