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
Post a Comment