jqtouch - How to find the id of an element using jQuery -
this html code
< body > < div id="map" >
i traversing parents until find body find map
var pagefrom= $(theelement).parentsuntil( 'body' ); var pagefromid = $(pagefrom).attr("id");
in firebug see pagefrom [div#map.current]
the problem pagefromid "" , should "map"
if you're using parentsuntil()
[docs] method, retuning collection of ancestors ordered nearest starting point farthest away.
because of this, you'll need access last 1 in collection id.
var pagefrom= $(theelement).parentsuntil( 'body' ); var pagefromid = pagefrom.last().attr('id');
or
var pagefrom= $(theelement).parentsuntil( 'body' ); var pagefromid = pagefrom.slice(-1).attr('id');
note can grab id property on element:
var pagefromid = pagefrom.get(-1).id;
Comments
Post a Comment