<div class="search_on" id="search-item">
<span class="text">one</span>
</div>
<ul class="search_item" style="display: none;">
<li><a href="#">one</a></li>
<li><a href="#">two</a></li>
<li><a href="#">three</a></li>
</ul>
jQuery code:
$('.search_item li a').click(function() {
$('#search-item .text').text() = $(this).text();
return false;
$('ul.search_item').hide();
});
I want to get:when the user clicks the a link which in the li label, then change the value in <span class="text">one</span> to the value in the a label. Why does the above code not work?
change
to
with
.text() = $(this).text()you are trying to set it like a property but it is a function so you need to call it like.text($(this).text())