javascript - set value for span using jquery - Stack Overflow

I have an <li> which have a field nameddata-resultcount.I need to select the data-resultcount

I have an <li> which have a field named data-resultcount.I need to select the data-resultcount value and print in the span.My <li> is

  <li id="totalCount" style="display:none" data-total="19" data-resultcount="19">totalCount</li>

and the <span> is

<div class="resultCount">Results:
    <span></span>
</div>

Thanks in advance for help

I have an <li> which have a field named data-resultcount.I need to select the data-resultcount value and print in the span.My <li> is

  <li id="totalCount" style="display:none" data-total="19" data-resultcount="19">totalCount</li>

and the <span> is

<div class="resultCount">Results:
    <span></span>
</div>

Thanks in advance for help

Share Improve this question edited Dec 24, 2013 at 6:58 Dhaval Marthak 17.4k6 gold badges48 silver badges69 bronze badges asked Dec 24, 2013 at 6:57 ArunArun 1,48212 gold badges34 silver badges59 bronze badges
Add a ment  | 

7 Answers 7

Reset to default 2

Try this:

html:

<div class="resultCount">Results:
    <span id ="mySpan"></span>
</div>

js:

document.getElementById("mySpan").innerHTML="Span text is changed";

Hope this helps.

You can use .data() to fetch value from data-resultcount

$('.resultCount').find('span').text($('#totalCount').data('resultcount'))

or

$('.resultCount span').text($('#totalCount').data('resultcount'))

Try

$('.resultCount span').text($('#totalCount').attr('data-resultcount'));

This will work :

$('.resultCount span').text($('li#totalCount').attr('data-resultcount'));

Use prop()method for better result:

$('.resultCount span').text($('li#totalCount').prop('data-resultcount'));

Try the following:

$(".resultCount").find('span:first').text($("#totalCount").attr('data-resultcount'))

Fiddle Sample

Try this

$(".resultCount").find('span').text($("#totalCount").attr('data-resultcount'))

Working Fiddle

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745162085a4614432.html

相关推荐

  • javascript - set value for span using jquery - Stack Overflow

    I have an <li> which have a field nameddata-resultcount.I need to select the data-resultcount

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信