<div id="content">
<textarea id="#example-1">
</textarea>
<textarea id="#example-2">
</textarea>
</div>
and Jquery
var xyz = $("content##example-1").val();
This code doesn’t work for me. It crashes – shows undefined. When I delete “#” from div from textarea and one “#” from JS code it works. It need to works with id with “#”.
Can I put variable into $() after quotation marks? E.g.:
$("content#"variable)
Escape the special character in the ID, and remove that
contentpart. Because element IDs must be unique, an ID selector will match at most one element. Therefore, anything beyond that is overspecified.Better still, don’t use a special character in the ID at all:
That’s not valid JavaScript; you need to use string concatenation. Also, the selector
'content'matches elements with tag namecontent, which is not what you want. Believe me: just get rid of thecontentpart entirely.Then use the
jqfunction described in the jQuery FAQ that I linked.