I'm trying to understand, how I could grab anchors title atribute, and insert it into input.
I tried this:
$(".choosebox a").click(function () {
var url = $(this).attr('title');
//alert(url);
$("input").text(url);
return false;
});
Alerting works great, but the title is not inserting inside the input.
What might be the correct way to do that?
P.S. If I want point开发者_开发技巧 to input one input, not all, then which syntax is appropriate? $("input[name='this-one']")
?
The problem is, probably, using text()
rather than val()
, an input
element doesn't really have a text()
content, rather it has a value
, which jQuery addresses as val()
, therefore this should work:
$(".choosebox a").click(function () {
var url = this.title; // Using the native JavaScript/DOM method for getting the title attribute.
//alert(url);
$("input[name='this-one']").val(url);
return false;
});
References:
text()
.val()
.- attribute-equals selector.
use instead
$("input").val(url);
精彩评论