when you are looping through all these tags what are you trying to do?
exclude certain tags or find them to manipulate? if trying to exclude you can do things like $(".specificClass *").not("img").hide() //hides all tags inside .specificClass except img's $(".specificClass *").find("img").hide()// hides only img's within .specificClass the need to check each element individually is probably not necessary and chances are you are under utilizing the power of jquery to do what you want. Here's an example: you are using this if statment: if ($("selector").is(":button")) { // do something } except it is very likely not necessary to test with if on every selector. If you do something like $(".specificClass button").css("color","red"); either this button is found within the class and color is made red,...... or no such element is found *and* nothing happens! no error, no failure of jquery perhaps throwing a few tasks up on this board that you are trying to accomplish would help, then see that some may be extremely easy to accomplish with not a lot of code cms4j wrote: Hello there, i have a couple of elements on my web page, that i want to manipulate in one loop.jQuery.each($(".specificClass"), function(i) { // do something } Within that loop i have to check what type of element that very one is e.g. a <div> or a <span> or an <img> or a <input type="button"> or something else. I managed to isolate some of them, the easiest was the button where i checked the following: if ($("selector").is(":button")) { // do something } In the jQuery API 1.3.2 there are some more useful Forms Filters like :input, :text, :checkbox etc. What i really miss is something for a drop down list. I would have expected that there is something like if ($("selector").is(":select")) { // do something } but i could not find it. It would also be great to have something to check if the element is an image. I have read that there exist such a check, but that is for images that are input-images within a form. I am longing for a simple check for an image somewhere in the web page. At the moment i build workarounds like this, but that is not really satisfying... if ( !isNullOrEmpty($("selector").attr("src"))) { // --- image --- // do something } if ($("selector")[0].selectedIndex >= 0) { // --- drop down list --- // do something } // convenience function like the one in C# window.isNullOrEmpty = function(obj) { return (obj === '' || obj === null || obj === undefined) } |
- [jQuery] find out if an element is a drop down list cms4j
- [jQuery] Re: find out if an element is a drop down list Charlie