Reputation:
I have a [WebMethod] that load an html snippet and add some content to it. That [WebMethod] is then injected into a page using $.post() and .html().
A piece of snippet:
<p id="name"></p>
The [WebMethod] add content to it:
<p id="name">Joe</p>
The snippet also contains a JavaScript code, like:
alert($("#id").text())
The problem: $("#id").text() return nothing (like in the snippet) but the content ("Joe") is showed correctly in the browser. Where is the problem?
Thanks and sorry for my EngRish.
Upvotes: 0
Views: 64
Reputation: 37137
you should call $("p#name")
instead of $("#id");
<p id="something"> </p>
$("p#something")...
<p class="something_else"></p>
$("p.something_else")...
Upvotes: 0
Reputation: 82483
Your element does not have an id of "id", it has an id of "name". Change your selector to this...
$("#name")
Upvotes: 4