Jump to content

How to refer to the element just below inside another element?


pstein

Recommended Posts

At first an example:

<div class="foobar" ....>....
  <div class="....." ...>.....
     <div class="....." ....>....
        <div class="....." ....>.....
           <img src="https:\\www.imgdomain.com\..." ....></img>
        ...</div>
     ....</div>
   ....</div>
....</div>

How do I address the following elements:

  1. Find <img> with src="https:\www.imgdomain.com* and go upwards in hierarchy until a <div> element with class="foobar" ist found

  2. Same as 1. but this time the element just below <div> with class="foobar" should be referred (which could be the <img> element itself)

If no <div> element with class="foobar" is found nothing should happen

jQuery or Javascript can be used

Link to comment
Share on other sites

As the target that you ultimately will want would be class element 'foobar' would it not be better to transverse down to img from that class name .

var x = document.querySelectorAll(".foobar img[src='https:\www.imgdomain.com']");

 

 

 

 

Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...