$(this).parent().parent().find(".imgHide").toggleClass("imgShow");
to javaScript
for parent() we can use parentElement
for toggleClass() we can use .classList.toggle("class")
but for .find() i am not able to get any alternative in vanilla js.
$(this).parent().parent().find(".imgHide").toggleClass("imgShow");
to javaScript
for parent() we can use parentElement
for toggleClass() we can use .classList.toggle("class")
but for .find() i am not able to get any alternative in vanilla js.
For further actions, you may consider blocking this person and/or reporting abuse
Gabor Szabo -
Mahmud R. Farhan -
Yuliana Sepúlveda Marín -
Chase Anderson -
Top comments (8)
A somewhat related element method is
closest
. This will help you find a parent, or the node itself, that matches the selector. This helps to make your code stronger against changes in your DOM structure (the .parent().parent() chain)developer.mozilla.org/en-US/docs/W...
i tried the closest method but it didnt worked
It wouldn't as looks in the opposite direction to jQuery's
find()
or the Web API'squerySelector[All]()
- which starts at theElement
and then looks at the descendent elements (away from the document root).The Web API's
closest()
is complementary as it starts at theElement
and then looks at the ancestor elements (towards the document root). See also jQuery's .closest().That being said querySelector() has been around longer than Element.closest().
okay now i understand, really thanks for the entire details, really appericiate your help
jQuery find()
vs
Document.querySelector()
Element.querySelector()
ParentNode.querySelector()
DocumentFragment.querySelector()
Document.querySelectorAll()
Element.querySelectorAll()
ParentNode.querySelectorAll()
DocumentFragment.querySelectorAll()
JavaScript basics: A Hello world! example
thanks for the info peerreynders
Googling "jquery .find vanilla js" gave the following result: stackoverflow.com/a/53824604
Maybe check it out and see if that works for you.
thanks for info Martini