Code: http://jsfiddle.net/qn7JG/1/
It is required when clicking on a link to pass this as a parameter in the onclick () function. And in the handler, add the name of the new class to this link. Tell me, please, how this can be done.
Code: http://jsfiddle.net/qn7JG/1/
It is required when clicking on a link to pass this as a parameter in the onclick () function. And in the handler, add the name of the new class to this link. Tell me, please, how this can be done.
Correctly: http://jsfiddle.net/qn7JG/22/
HTML:
<div id="res"> <a href="" class="ff" data-lat="123" data-lon="321" data-balloontext="text123">textr123</a> </div> Js:
$("a").click(function(e){ var $this = $(this); $this.addClass("selected"); console.log($this.data("lat")); console.log($this.data("lon")); console.log($this.data("balloontext")); e.preventDefault(); }); If you are already using jQuery , then do it in jQuery style:
$('a').on('click', function(e) { $(this).addClass('selected'); e.preventDefault(); // отменяем действия перехода }); If you want to transfer some additional parameters, use the data attribute:
html :
<a href='#' data-number="10" data-class="selected"></a> js :
$('a').on('click', function(e) { $(this).addClass($(this).data('class')); e.preventDefault(); // отменяем действия перехода }); In your case, you need to do this:
<a href="" class="ff" onclick="return go_to(123, 321,'text123', this, event)">textr123</a> That is, add the event parameter to the function call. Plus, jsfiddle not your working code, since The go_to function is not located in the global scope. Remove it from window.onload .
Source: https://ru.stackoverflow.com/questions/349672/
All Articles