javascript - Variable in Selector -


i have code:

<script> jquery(document).ready(function ($) {    $("#menu-item-7285 .sub-menu li").click(function (e) {       var str = $('a', this).attr('href').split('#')[1];       $('a[href$=str]').closest("li").addclass("active");       $('html,body').animate({          scrolltop: $(window).scrolltop() + 800       });    }); }); </script> 

this part giving me trouble: $('a[href$=str]'). correct way include str variable?

you're looking $('a[href$=' + str + ']'), simple string concatenation.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -