Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
-7
rated 0 times [  0] [ 7]  / answers: 1 / hits: 156556  / 10 Years ago, mon, february 17, 2014, 12:00:00

I'm working on a site with a visualization of inheritance relation.



I try to link each nodebox with specific URLs. The html of Element looks like this:



<g class=node id=RootNode transform=translate(0,453.125)>


I used



$('#RootNode').click(function(){//do something}


and also



document.getElementById(RootNode).onclick(){//do something}


Neither of them can find the element, nor setup the onclick function.



Have I misunderstood anything? Any information will be helpful. Thanks.


More From » jquery

 Answers
50

Make sure your code is in DOM Ready as pointed by rocket-hazmat



.click()



$('#RootNode').click(function(){
//do something
});





document.getElementById(RootNode).onclick = function(){//do something}




.on()



Use event Delegation/



$(document).on(click, #RootNode, function(){
//do something
});




Try



Wrap Code in Dom Ready



$(document).ready(function(){
$('#RootNode').click(function(){
//do something
});
});

[#72481] Saturday, February 15, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinadomoniquel

Total Points: 320
Total Questions: 94
Total Answers: 94

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
;