If you've got other td
's on the page that don't contain a span
, you'll probably want to use the :has
selector to make sure you're only binding to td
that has a span
child.
$('td:has(span)').mouseover(function(e) {
var content = $(this).find('span').html(); //or .text() for the plain text
//do something with the content
});
I think you're probably better off giving either the td
or the span
a semantic class though, it'll make the intent of your HTML a bit more obvious. Something like
<td>
Some stuff here
<span class="sekret" style="display: none;">sekret stuff here</span>
</td>
... and modify the selector in the javascript to be something like
$('td:has(.sekret)').mouseover(...