jQuery this.text not working in IE after live event
I am currently trying to update my website with some jQuery functions. As allways with web development IE is being a pain.
I have an autosuggestion list that looks like this:
<div id="suggestionBox">
<ul>
<li>
<a class="entry" style="display:block;" href="#">somesuggestion</a>
</li>
...
</ul
</div>
Of course, the suggestions are gained from a server, so I use a load() function every time the input field is changed. This works all fine. The problem is, I want the input field to be completed when a suggestion is clicked. I use the following code for that:
$(".entry").live('click', function() {
$("#" + $("#suggestionBox").data('input')).val(this.text);
//and some more stuff
});
The data field for the suggestionBox is set when the input field gets focus.
I开发者_开发百科t works perfectly fine in Chrome, and FireFox but not in IE. this.text in the above code returns undefined.
I have no clue why this shouldn't work for IE. Can anyone help me?
Thanks.
Why don't you use jQuery?
$(this).text()
An a
element has no text
property in IE.
You need to use jQuery's text()
function, not property, since the underlying DOM property is browser-specific:
$("#" + $("#suggestionBox").data('input')).val($(this).text());
精彩评论