I’m trying to use Coffeescrip/jQuery to iterate through every span on a page and return the text enclosed between a particular span’s tags if the id of that span is equal to the variable elemId. Here’s what I have:
elemValue = $('span').each ->
$(@).text() if $(@).attr("id") is elemId
For some reason, though, this only returns [object Object] for the elemValue that I output to the page, even when I test it on a page that I know has a span with that elemId. Any idea where I’m going wrong?
Also, how to set a default value for elemValue, in case there is no span on the page has an id that is the same as elemId?
if you know the id then why are you iterating whole span. just use id to get text