简体   繁体   中英

how to select an element from one div to another?

I am trying to do select an anchor from one div to another using next() , shiblings(), parents(), parent() etc jquery functions

Here is an example of html

<div class="thumbs">
   <div class="section">
      <div class="wrap">
         <a href="link.php" data-selector="ajax">HOme</a>
      </div>
   </div>
<div>
<div class="thumbs">
   <div class="section">
      <div class="wrap">
         <a href="link2.php" data-selector="ajax">about</a>
      </div>
   </div>
<div>

i want to get the second link.Suppose my current link is link.php and when i click th next button i want to get next link2.php link

You need to use:

$('[data-selector="ajax"].current')
      .closest('.thumbs')
          .next()
             .find('a')
               .attr("href"); // will return link2.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM