简体   繁体   中英

my traversal jquery don't work

travel from .statPlus to select .secondTab, take a look on my js below.. In console.log(path), it show its own..

<div class='secondTab'>
    <div id='stat1' class='progress-radial progress-78'>
        <div class='profilePicture'></div>  <a href='#' class='percent'>78%</a>

    </div>
</div>
<!-- secondTab-->
<div class='statPlusWrap'>
    <div class='statPlus'>+</div>
</div>

js

  $(".statPlus").on('click', function () {
      var path = $(this).closest('statPlusWrap').prev('secondTab');
  });

You need a dot in your selectors, because you're selecting a class:

$(".statPlus").on('click', function () {
    var path = $(this).closest('.statPlusWrap').prev('.secondTab');
});

You need to use a . for selecting classes, like this:

var path = $(this).closest('.statPlusWrap').prev('.secondTab');

Here is a working example

Typo missing . in class selector

var path = $(this).closest('.statPlusWrap').prev('.secondTab');
                            ^// missing dot for class selector 

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