Tench
2005-Jul-28 09:43 UTC
[Rails-spinoffs] autocomplete: how to access a child element of <li>
hi. i promise this will be my last question for the day. still playing with autocompleter, everything is working ok, but i''m having difficulties accessing just the href attribute of <a> element, which is a child of <li> in the autocomplete response, i.e: <div class ="autocomplete"> <ul> <li><a href ="overtherainbow.html">somewhere</a></li> </ul> </div> i thought i could do something like el = Event.findElement(event, ''LI''); href = el.firstChild.getAttribute(''href''); but that''s not it... if anybody can awake me from my dogmatic slumber, i will greatly appreciate it... all best, tench
Faust
2005-Jul-28 10:28 UTC
[Rails-spinoffs] autocomplete: how to access a child element of <li>
Tench wrote:> i thought i could do something like > > el = Event.findElement(event, ''LI''); > href = el.firstChild.getAttribute(''href''); > > but that''s not it...I haven''t been following this conversation, so I may be way out of line. But I think you want to do something more like this: href = el.getElementsByTagName(''a'')[0].getAttribute(''href''); or href = el.getElementsByTagName(''a'')[0].href; See Stuart Langridge''s ''DHTML Utopia: Modern Web Design Using JavaScript & DOM'' <http://www.sitepoint.com/article/dhtml-utopia-modern-web-design/2> for a DOM primer. HTH, Faust
Martin Bialasinski
2005-Jul-28 10:39 UTC
[Rails-spinoffs] autocomplete: how to access a child element of <li>
On 28/07/05, Tench <psychomachine@mac.com> wrote:> having difficulties accessing just the href attribute of <a> element, > which is a child of <li> in the autocomplete response, i.e: > > <div class ="autocomplete"> > <ul> > <li><a href ="overtherainbow.html">somewhere</a></li> > </ul> > </div> > > i thought i could do something like > > el = Event.findElement(event, ''LI''); > href = el.firstChild.getAttribute(''href''); > > but that''s not it...For the example above, this should work. But if there is any text between <li> and <a>, the firstChild will be a text node. Depending on the browser, even just spaces/newline between them creates a text node. Bye, Martin
Apparently Analagous Threads
- cross-fade effect on elements updated by ajax.updater?
- Ajax.InPlaceEditor on Safari & Firefox
- safari vs. firefox on mac os x: flickering combination effects
- Rails newbie: How does the submit_tag work?
- why is the result of expr. Ajax.InPlaceEditor not an object in Safari