1

I am attempting to use data from an html page in js.coffee script.

The view code is:

 <span class="colHeader" data-wostatus-id="<%= wostatus.id %>"><span><%= wostatus.statuscode %></span></span>

Inspecting html looks like this:

<span class="colHeader" data-wostatus-id="4"><span>WAPR</span></span>

So far, so good.

My js.coffee file has:

     alert($(this).data('wostatus-id'))

And the results I get = undefined

Thanks for the help!

3
  • What about alert($(this).getAttribute('data-wostatus-id'))? Commented Jan 8, 2013 at 15:50
  • 1
    What is this here? Looks like it's bound to wrong node. Commented Jan 8, 2013 at 16:21
  • Sailor - that didn't work either. Commented Jan 8, 2013 at 17:12

2 Answers 2

1

Try this in your js.coffee file. It will run only when the DOM is ready, and specifically accesses the span element:

$ ->
  alert($('span.colHeader').data('wostatus-id'))
Sign up to request clarification or add additional context in comments.

Comments

0

Simply use jQuery and scan the document for whatever has the id:

jQuery("[data-wostatus-id]").each (index, elm) ->
    alert(jQuery(elm).attr("data-wostatus-id"))

This presumes there are multiple 'ids' on the page (thus the each)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.