开发者

Setting a number between tags as a variable

开发者 https://www.devze.com 2023-03-12 01:55 出处:网络
I\'m trying to get a number (x) inside tags, ie: <span id=\"Number\">x</span> a开发者_开发百科nd set that as a variable.

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号