1
$('#content #home nav #navigationList li:nth-child(2) a').trigger("click");  
$('#content #home nav #navigationList li:nth-child(2) a').css("background", "red");

I'm trying to create an event trigger click on an "" the secletor work pretty well in the console of firefox but not in my js file. The same selector with a .css() work without any problem. Need some help can someone explain me why.

My problem is my navigation bar

i wanted this http://gontranachille.com/en/about about is not a folder it is a section in a singlepage website i wanted if the user put this link http://gontranachille.com/en/about the website scroll automatically to the section i manage to do it it work with the css color change but not with the trigger and it is the same selector and in the console of firefox it works also......

rodolphe
  • 33
  • 7

1 Answers1

0

trigger("click") triggers your click function in js. If you want to go a's href link. You can use below code.

location.href = $('#content #home nav #navigationList li:nth-child(2) a').attr("href");
ebilgin
  • 1,242
  • 10
  • 19
  • $('#content #home nav #navigationList li:nth-child(2) a')[0].click(); – rodolphe Aug 11 '15 at 14:25
  • Also this work but i need to perform all my calculation again for the navigation bar because it is a fix one.. I think it is the only way – rodolphe Aug 11 '15 at 14:26
  • What calculation exactly? For further help please provide more code. – ebilgin Aug 11 '15 at 14:29
  • my code work perfectly it was just an error from my part i was calling my scroll function after the trigger click. So trigger click work also perfectly on thanks you for your help all of you. I can't put the subjet solve it says i need more reputation. I don't know how i could manage to do it. – rodolphe Aug 12 '15 at 08:40