Reputation: 203
I want to get id and text name of each li in ul using jquery
I have tried this but it didn't work
<ul id="tags1">
@foreach (var item in Model.Tags)
{
<li [email protected] >@item.TagName</li>
}
</ul>
I have tried this code but it gave me a lot or html
$('#tags1 li').each(function (i) {
alert($(this).html());
console.log($(this).html());
});
It gave me that
<span class="tagit-label">Art</span><a class="tagit-close"><span class="text-icon">×</span><span class="ui-icon ui-icon-close"></span></a><input type="hidden" style="display:none;" value="Art" name="tags">
I just need to get the value only value="Art"
Thank you
Upvotes: 0
Views: 5024
Reputation: 1651
$('#tags1 li').each(function () {
console.log(this.id);
console.log($(this).text());
});
Upvotes: 0
Reputation: 20740
You can do it like following.
$('#tags1 li').each(function () {
console.log(this.id); //id
console.log($('.tagit-label', this).text()); //text
});
Upvotes: 2