Let’s start with simple selecting. We may need a list of all the images in a document. This can be achieved very easy:
$("img")
$("img").hide();
Now, if we don’t want all images but only images located in div tag we can do this:
$("div > img").hide();
$("#myId")
$("#myId > img")
$("div .text").hide();
If we get a list of elements from another source (for example some function) and we want to obtain only the ones with a exact property we can do it with filter. In this example I’ll select all div elements and check them:
$("div").filter(".text").hide();
After hiding all elements we may want to show the first one. Here we have several approaches. If the circumstances are right we can just select the first element:
$(".text:first").show();
$(".text:last").show();
var n = 1; // we want the second element in reality $("div:eq("+n+")").show();
$("div:contains(text)"). css("background-color","yellow");
$("div:contains(text):not(.title)"). css("background-color","yellow");
No comments:
Post a Comment