It may be something very simple, but I can't get it to work, and I'm not sure why. I have jquery installed and I'm trying to get the attribute of the "this" element when I click on it. My code now looks like this:
url = $(this).attr("href")
When I call this function by clicking on the link, it tells me that var "url" is undefined. Thus, it is obvious that it does not pick up "this" when I click on the link. I am trying to pass href binding labels to use as my variable.
What am I missing? Again, I know this is something very simple, but I canβt figure it out, so thanks for taking the time to help me.
Thanks.
<script type="text/javascript"> url = "push1"; $("a").live("click", function(event) { event.preventDefault(); url = $(this).attr("href"); }) $.ajax({ type: "get", url: "/"+url+".php", data: "", dataType: "html", success: function(html){ jQuery('#Right_Content').hide().html(html).fadeIn(1000); }, }) ; </script>
HTML:
<body> <a href="push1" >Image 1</a> <a href="push2" >Image 2</a> <div id="Right_Content"></div> </body>
source share