javascript - Why is .nextAll() not returning the expected elements? -
i'm pretty new javascript/jquery. trying understand going wrong following code?:
javascript:
$('.rating-stars').each(function() { var currentscore = $(this).nextall('.current-score'); console.log(currentscore); $('.rating-stars').barrating('show', { theme: 'fontawesome-stars-o', deselectable: false, showselectedrating: false, initialrating: currentscore, }); });
html:
<form id="vote_form" class="form-inline" method="post" action="/y/update_rating/39"> <span class="h3"><a href="#">title</a></span> <select class="rating-stars" id="id_vote" name="vote"> <option value=""></option> <option value="1"></option> <option value="2"></option> <option value="3"></option> <option value="4"></option> <option value="5"></option> </select> <span class="current-score">4.0</span> </form>
in short, have element class .rating-stars element class .current-score next it displays score/integer.
i want set initialrating number displayed .current-score element.
(as can guess code, there more 1 rating displayed on page, hence .each function)
currently, console.log
returning:
[select#id_vote.rating-stars, context: select#id_vote.rating-stars]0: select#id_vote.rating-starscontext: select#id_vote.rating-starslength: 1__proto__: object[0] ratings.js:7 [select#id_vote.rating-stars, context: select#id_vote.rating-stars]
with of comments on answer have come solution:
i misunderstanding .next() — didn't realize looked siblings, thought read through top bottom, not in hierarchical fashion.
i needed add .parent() variable before .next or .nextall call:
var currentscore = $(this).parent().next('.current-score').html();
Comments
Post a Comment