I\’m fairly new to jQuery and want to move past using explicit selectors and muddying up my code this way. I have tried a few different things but am unsuccessful at getting my selectors to dynamically function on multiple elements without having a snippet of code for each element.
My script is simply as follows:
<script type=\"text/javascript\">
$(document).ready(function() {
$(\"#navItem\").mouseenter(function(){
$(this).animate({
height: \"150px\"
}, 500, \"easeOutBounce\")
})
$(\"#navItem\").mouseleave(function(){
$(this).animate({
height: \"120px\"
}, 500, \"easeOutBounce\")
})
</script>
And my HTML..
<div class=\"navWrap\">
<div id=\"navItem\" class=\"navButton blue\"></div>
<div id=\"navItem2\" class=\"navButton orange\"></div>
<div id=\"navItem3\" class=\"navButton green\"></div>
<div id=\"navItem4\" class=\"navButton red\"></div>
</div>
I left out the remainder of the script because it\’s repetitive (the same functions for the rest of the IDs you see in the HTML). My goal is to be able to dynamically select the \”current\” element that is being hovered over, rather than explicitly referencing each ID. I assume I need to use the \”this\” selector, but the documentation I\’ve found I have trouble relating back to my scenario.
Any help is appreciated, thanks all!





Rating:
The post javascript – Using dynamic jQuery selectors appeared first on Javascript ASK.
via Javascript ASK http://javascriptask.phpfogapp.com/javascript-using-dynamic-jquery-selectors.html
No comments:
Post a Comment