Reputation: 1472
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
Upvotes: 0
Views: 2756
Reputation: 853
Try the following:
$(".resultCount").find('span:first').text($("#totalCount").attr('data-resultcount'))
Upvotes: 1
Reputation: 2170
Try this
$(".resultCount").find('span').text($("#totalCount").attr('data-resultcount'))
Upvotes: 0
Reputation: 85545
Use prop()method for better result:
$('.resultCount span').text($('li#totalCount').prop('data-resultcount'));
Upvotes: 1
Reputation: 3563
This will work :
$('.resultCount span').text($('li#totalCount').attr('data-resultcount'));
Upvotes: 1
Reputation: 10694
Try
$('.resultCount span').text($('#totalCount').attr('data-resultcount'));
Upvotes: 1
Reputation: 133403
You can use .data()
to fetch value from data-resultcount
$('.resultCount').find('span').text($('#totalCount').data('resultcount'))
or
$('.resultCount span').text($('#totalCount').data('resultcount'))
Upvotes: 2
Reputation: 28823
Try this:
html:
<div class="resultCount">Results:
<span id ="mySpan"></span>
</div>
js:
document.getElementById("mySpan").innerHTML="Span text is changed";
Hope this helps.
Upvotes: 2