Reza San Reza San - 1 year ago 68
Javascript Question

jQuery : Get content of id

Need some help with jQuery DOM.
I need to extract the content of the id. I have a list that user can select and it will filter the

of the map. After user select, I want
to display the new selected filter. I can apply the "id" to the filter title but not sure about the content because the content has Shopping / Dining. Someone please.


<div class="map-filter">
<div class="filtertitle">All Categories</div>
<ul class="filter-list">
<li class="active" id="All Categories">All Categories</li>
<li id="Shopping">Shopping/Dining</li>
<li id="Hotel">Hotels & Resorts</li>
<li id="Art">Art Galleries</li>


$('.filter-list li').click(function(){
var id = $(this).attr('id');
$('.filtertitle').html(id); //This part is where I set the id

Answer Source

Use .text(), it gives you the text content of the desired element.


In case of html content use .html().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download