javascript - how to identify the element that was clicked? -
please help prepare script.
after user clicks on item .menu_button, there phone call function initform(). function should print 1
console.log(n)
but displays 3:
console.log(1) console.log(2) console.log(3)
i not understand
js:
$(document).ready(function() { // --- plugin kalininmodals initialization --- $('.menu_button').kalininmodals(); ); (function($){ // --- options --- $.fn.kalininmodals = function(options) { var options = $.extend({},options); homecoming this.each(function(e) { // --- properties --- var self = $(this), selfmodals = $('#modalouter'), selfmodalswindow = $('#modalwindow'), head, info, actionsarr; // --- methods --- function initform(formnum){ //console.log('___' + self.text()); if(formnum == 1){ console.log(1); head = 'Обратный звонок'; } else if(formnum == 2){ console.log(2); head = 'Обратный звонок'; } else if(formnum == 3){ console.log(3); head = 'Обратный звонок'; }; } function makebody(){ console.log('make'); $('#head .h2').text(head); $('#info').html(info); } // --- handlers --- function onclickcontrols(e){ self = $(e.currenttarget); initform(self.attr('data-form-num')); makebody(); } // --- events --- $('#menubutton1, #menubutton2, #menubutton3').on('click', onclickcontrols); }); }; })($);
make utilize of class
<div class="menubutton">menu 1</div> <div class="menubutton">menu 2</div> <div class="menubutton">menu 3</div>
and in jquery
$(document).ready(function(){ $(".menubutton").click(function(){ alert($(this).html()); }); });
hope helps!
javascript jquery
No comments:
Post a Comment