开发者

How to get the value of span tag based on css class in jquery?

开发者 https://www.devze.com 2023-01-06 03:22 出处:网络
How to get the value of span tag based on css class in jquery? <span class=\"page-numbers current\">3</span>

How to get the value of span tag based on css class in jquery?

<span class="page-numbers current">3</span>

I used

var pageno = $(".page-numbers current").val();
  alert(pageno);

it doesnt seem to work.any suggestion..

EDIT:i am using 开发者_运维知识库jquery pagination plugin for pagination... for first page 1 and prev are assigned css class class="page-numbers current

<span class="page-numbers current prev">Prev</span>
<span class="page-numbers current">1</span>


".page-numbers" and "current" are 2 different css classes.

Your jQuery expects "current" to be inside of ".page-numbers".

Also use text() for non-input elements.

This should work

alert($(".page-numbers").text());

EDIT: Furthermore, current hasn't got a class (.) or id (#) prefix which means it's looking for an element "current", which doesn't exist. Use #current or .current


var pageno = $(".page-numbers.current").text();
  alert(pageno);

see second example class-selector


I assume only the current page was the class .current so grab it using only that selector.

Grab it using jQuery .html() like this:

// do notice that a . was added to class .current!
var pageno = $(".current").html();
alert(pageno);


You were trying to capture the val that exists in fields like input.

// on a field like this what you were doing would work perfectly
<input type='text' val='12' />
0

精彩评论

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