开发者

How to use jquery selector having element type and ID

I'm using this selector $("textarea #myTextArea").val(text); and it's not working. If I remove the ID and use the class it's working. Why isn't jquer开发者_如何转开发y able to find the element here?


Because of the space. With the space it says the #myTextArea within a textarea.

$("textarea#myTextArea").val(text);


Just remove the space:

$("textarea#myTextArea").val(text);

At the moment you're trying to select an element with ID myTextArea that is a descendant element of a textarea

As Jared Farrish mentions in the comments removing the element type would be more efficient:

$("#myTextArea").val(text);

If your document is valid then every ID will only used be once so this is still correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜