cs0815
cs0815

Reputation: 17388

Hidden div issue

I have a div which I intend to hide like this:

$("#bla").hide();

until some jQuery code fills it with data. This seems to break the 'filling code'. Hiding should still allow the 'filling code' to access the HTML or am I missing something?

Upvotes: 1

Views: 61

Answers (2)

Benjamin Gruenbaum
Benjamin Gruenbaum

Reputation: 276286

Yes, Hiding a div still allows 'filling code' in it.

From the doc

This is roughly equivalent to calling .css('display', 'none'), except that the value of the display property is saved in jQuery's data cache so that display can later be restored to its initial value.

What you're doing is basically just telling the web-page not to display your element. It is still a part of the DOM. You can access its html and such. You can use .show to show it later

For example:

var elem = $("#bla");
elem.hide();//hides the element
elem.text("Hello World");//sets its inner text to "Hello World"
elem.show(); // "Shows the element again"

Here is another interesting question about how hide/show is implemented

Upvotes: 2

bipen
bipen

Reputation: 36531

hide has nothing to do with breaking your fillin code, hide just adds display:none to the element and does not remove it form the DOM..so filling it with other method won't break at all.... however, check for other javascript issues...other issue might break it..

here is the example in fiddle

try this

$("#bla").hide();
$("#bla").text('asdasdasdsds');
console.log($("#bla").text())

check your console..

Upvotes: 2

Related Questions