How do i write this selector in plain javascript
$(this).parent('p')
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since the jQuery
.parent(selector)function only checks the immediate parent, you can create a function like this:Then, you can just call this:
Or, if you want it to return an array similar to how jQuery does it, you would use this:
Then, you can just call this (and get an array back):
If you wanted the equivalent of the jQuery
.parents(selector)function that returns all ancestors that match a tag type, you would use this:And, you would call it like this: