I have this code:
<script>
function del(a){
alert(a);
alert($("#"+a).html());
alert($("#td").html());
alert($("#div").html());
}
</script>
<td id="td">wtf</td>
<div id="div">wtf</div>
<table>
<tr>
<td id="bbbbb">test</td><td><span onclick="del('bbbb');">click</span></td>
</tr>
</table>
Alerts are
bbbbb
test
null
wtf
td content is marked as null (ignored) ?
Why?
proof http://sandbox.phpcode.eu/g/743de.php
UPDATE:
look here
and my alert gives me null, too
First off, you cannot have
<td>elements outside of a table, but it seems in your update, you’ve fixed that.In your latest update, the fiddle you posted returns null because of how jQuery selectors work. The ID you are looking for is “5c192.php”, so when you do
$('#'+a)it becomes$('#5c192.php'), which is being interpreted as ‘ID=5c192’ and ‘class=php’, because.is a class selector.Change
$('#'+a)to$('[id="'+a+'"]').