tags:

views:

39

answers:

2

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.

+4  A: 

Your element does not have an id of "id", it has an id of "name". Change your selector to this...

$("#name")
Josh Stodola
A: 

you should call $("p#name") instead of $("#id");

<p id="something"> </p>
$("p#something")...

<p class="something_else"></p>
$("p.something_else")...
fmsf