Jump to content

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


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...