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 badges7 Answers
Reset to default 2Try 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
评论列表(0条)