Topic: getAttribute using RJS

Hi there

I need to get a property from a div tag using RJS.  For example,

the page has <div id="foo" trogdor="bar">

I need a way of getting the value of trogdor somehow and then pass it into a page.replace_html().  Any help would be greatly appreciated!

Last edited by totallygirl (2007-11-01 17:26:35)

Re: getAttribute using RJS

Prototype already implements methods of finding divs based on their ID, and it's really easy to do so. You should use a div's ID, then, rather than some arbitrary attribute, to call it during RJS. The DOM reference doesn't even specify ways to get elements by methods other than tag, name, class, and id.

If you HAD to do this using some irregular method, then I would investigate iterating over every element of the page and using the Prototype readAttribute method to find the value of trogdor and check it. This is definitely JavaScript's realm, though, and not Rails'.

Use the id, not trogdor, to find this div.

Re: getAttribute using RJS

thanks for the reply veraticus.  I think you misunderstood me a little bit... I can easily find the div but I need to get the value of another attribute in the tag (trodgor) and pass that into a page.replace_html call as a locals variable. 

<div id="theDivName" trogdor="5">blah blah</div>

testing_id = page['theDivName'].getAttribute('trogdor')

  :partial => "some_partial",
  :locals => {:passing_testing_id => testing_id

Last edited by totallygirl (2007-11-01 18:02:40)

Re: getAttribute using RJS

Oh! Then readAttribute should be exactly what you need.