jquery - Find an element by class name, from a known parent element -
I have to find an element by the class name. I know that it will appear in a particular parent device, instead of searching the entire dom, I just want to find a specific device. I'm trying it, but it does not seem to be the right syntax:
< Code> var element = $ ("# parentDiv"). ("MyClassNameOfInterest"); What is the correct way to do this?
Thank you
You were close to you:
var element = $ ("# parentDiv"). Find ("MyClassNameOfInterest"); -
.find ()-
Alternatively, you can:
var element = $ (". MyClassNameOfInterest", "#parentDiv"); ... that sets the context of the jQuery object's #parentDiv .
Edit:
Additionally, if you select div.myClassNameOfInterest instead of just .myclassNameOfInterest , Then it may be faster in some browsers.
Comments
Post a Comment