Reputation: 2587
In jQuery I want to say at any time this DOM element shows up do this. So kinda like .live() or .on() at any time the DOM element is found, hide it.
Upvotes: 2
Views: 101
Reputation: 207861
You don't need jQuery, just use CSS. Even if the element is generated after the page is created the CSS will be applied. Ex: http://jsfiddle.net/YB2bk/. In this example, a page has one div that when clicked, creates a new div. Both divs get the same CSS applied.
Upvotes: 0
Reputation: 250812
Say you wanted to achieve this...
if (myCondition) {
$(".myClass").hide();
}
But you don't know when the myClass
item will show up, you could do the following:
CSS:
.shouldHide .myClass {
display: none;
}
jQuery:
if (myCondition) {
$("body").addClass("shouldHide");
}
This means you can still apply the condition by adding / removing the shouldHide
class on the body tag, and you have a CSS rule that will hide myClass
if the body tag has the shouldHide
class.
Upvotes: 2