Reputation: 33
<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?
Upvotes: 1
Views: 180
Reputation: 9869
Change statement
$('#search-item .text').text() = $(this).text();
to
$('#search-item .text').text($(this).text());
and move return false
statement, after $('ul.search_item').hide();
if you want to hide ul.search_item
after setting the text.
Upvotes: 4
Reputation: 40512
change
$('#search-item .text').text() = $(this).text();
to
$('#search-item .text').text($(this).text());
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())
Upvotes: 1
Reputation: 337743
You need to pass the text()
value as a parameter. like this:
$('#search-item .text').text($(this).text());
Upvotes: 1