I'm trying to get a number (x
) inside tags, ie: <span id="Number">x</span>
a开发者_开发百科nd set that as a variable.
Am I even on the right track with this? Not even close?
var y = $('#Number').nextUntil('span');
If you want the content of the span, do this:
var y = $('#Number').text();
You need to think of them as whole elements, not individual opening/closing tags. The text()
[docs] method gives you the text content of the span
element you selected by ID.
The code above will give you a String. If you want a Number, you can convert it like this:
var y = parseInt( $('#Number').text(), 10);
or this:
var y = +$('#Number').text();
精彩评论