PDA

View Full Version : Modifying DOM Elements



jnotti
22 Nov 2011, 2:18 PM
I understand that this is possible but I can't find a simple implementation anywhere. Granted I am somewhat new and coming from jQuery, I am so frustrated that I can't pull this together without some crazy obscure function. How can I get the href of any link that has been tapped within .content?

<div class="content">
<a href="http://link.com">link</a>
</div>

mitchellsimoens
23 Nov 2011, 11:19 AM
var el = Ext.get('someEl');

el.on('click', function(e, t, opts) {
e.stopEvent(); //stops the event so it doesn't follow the link

var el = e.getTarget('a', null, true); //returns Ext.Element instance for a child matching the selector 'a' which is the link

console.log(el.getAttribute('href')); //logs out something.php
});




<html>
<!-- other stuff -->
<body>
<div id='someEl' class='someCls'>
<a href='something.php'>Something</a>
</div>
</body>
</html>

jnotti
23 Nov 2011, 11:25 AM
Now it all makes sense, I appreciate that, thank you very much!

Follow-up question... when obtaining a reference to an element, in your example you are targeting the ID, is it possible to use a class? I recall something that mentioned using an ID had some downsides associated with it, though I don't remember the source.

Anyway, thank you... Happy Holidays!

mitchellsimoens
23 Nov 2011, 1:42 PM
You can use a class but you will have to iterate from the body and if you have two with teh same, you have to make sure you use the correct one.