onclick

single onclick function for buttons with a similar id pattern - JavaScript

こ雲淡風輕ζ 提交于 2019-12-31 02:02:12
问题 I want to reduce the code. function one() { console.log("hai"); } document.getElementById('dealsButton_1').onclick = one; document.getElementById('dealsButton_2').onclick = one; //I want the above 2 lines of code reduced to one. A single function for on click on 'dealsButton_*' patterned id elements. How can I do this. The elements are dynamically loaded . 回答1: You can use querySelectorAll and the selector [id^=dealsButton_] to add the event listener in a single line - see demo below:

click on a div with regular javascript

孤街浪徒 提交于 2019-12-30 22:52:44
问题 jquery attaches a click method on even things that aren't typically clickable like a DIV. this can be great because some things respond to that. How can i "click" on any old regular DIV using plain old javascript without Jquery? what i am trying to do is trigger clicking on the area where the user can post in Jquery. I'm using a chrome extension that can run some javascript on a hotkey. I wrote a jquery version var x = $('div[guidedhelpid="sharebox"]'); x.click(); which works fine, other than

click on a div with regular javascript

橙三吉。 提交于 2019-12-30 22:52:30
问题 jquery attaches a click method on even things that aren't typically clickable like a DIV. this can be great because some things respond to that. How can i "click" on any old regular DIV using plain old javascript without Jquery? what i am trying to do is trigger clicking on the area where the user can post in Jquery. I'm using a chrome extension that can run some javascript on a hotkey. I wrote a jquery version var x = $('div[guidedhelpid="sharebox"]'); x.click(); which works fine, other than

click() jquery function not available on new divs

空扰寡人 提交于 2019-12-30 22:26:32
问题 During the running of my website i create new divs using jquery with class "a". I have defined a click() function for "a" class as follows: $(document).ready(function() { $(".a").click(function(){ $(".a").hide(); }); }); Problem is that the new divs created with the same class do not call this function when clicked. Other divs with "a" class which are there at the beginning do. What am I doing wrong? 回答1: $(document).delegate('.a', 'click', function() { $(this).hide(); }); 回答2: Try using the

click() jquery function not available on new divs

谁说我不能喝 提交于 2019-12-30 22:26:13
问题 During the running of my website i create new divs using jquery with class "a". I have defined a click() function for "a" class as follows: $(document).ready(function() { $(".a").click(function(){ $(".a").hide(); }); }); Problem is that the new divs created with the same class do not call this function when clicked. Other divs with "a" class which are there at the beginning do. What am I doing wrong? 回答1: $(document).delegate('.a', 'click', function() { $(this).hide(); }); 回答2: Try using the

click() jquery function not available on new divs

限于喜欢 提交于 2019-12-30 22:26:05
问题 During the running of my website i create new divs using jquery with class "a". I have defined a click() function for "a" class as follows: $(document).ready(function() { $(".a").click(function(){ $(".a").hide(); }); }); Problem is that the new divs created with the same class do not call this function when clicked. Other divs with "a" class which are there at the beginning do. What am I doing wrong? 回答1: $(document).delegate('.a', 'click', function() { $(this).hide(); }); 回答2: Try using the

JavaScript onclick requires two clicks

萝らか妹 提交于 2019-12-30 14:19:22
问题 My problem is that when onclick triggers the toggleNew function it's not executing but when I click the div a second time it's executing just as it should... HTML: <div id="aside_main"> <div onclick="toggleNew();">click</div> content </div> <div id="aside_new"> content </div> JS: function toggleNew() { var e = document.getElementById('aside_main'); var se = document.getElementById('aside_new'); if(e.style.display == 'block') { e.style.display = 'none'; se.style.display = 'block'; } else { e

android - giving onTouch priority over onClick

混江龙づ霸主 提交于 2019-12-30 10:48:09
问题 I have an activity that allows users to swipe between 3 different views. Each view displays a list of images. The images have onClick events that call a new activity and makes the images full screen. This all works ok however if I try to swipe between the 3 different views and my finger swipes over an image it will trigger the onClick event and open the image fullscreen. So I am wondering how can I put priority on onTouch (for the page/view swapping) ? (the onTouch event uses a

mixing my jQuery click events with existing object's onclick attribute

早过忘川 提交于 2019-12-30 10:45:10
问题 I'm using jQuery but dealing with markup produced from JSF pages. A lot of the elements have onclick attributes provided by the JSF code (which isn't my realm). Example: <div onclick="[jsf js to submit form and go to next page]">submit</div> I'm trying to add some client side validation with jQuery. I need something like this pseudo code: $('div').click(function(e){ if(myValidation==true){ // do nothing and let the JS in the onlick attribute do its thing } else { $error.show(); // somehow

mixing my jQuery click events with existing object's onclick attribute

空扰寡人 提交于 2019-12-30 10:45:06
问题 I'm using jQuery but dealing with markup produced from JSF pages. A lot of the elements have onclick attributes provided by the JSF code (which isn't my realm). Example: <div onclick="[jsf js to submit form and go to next page]">submit</div> I'm trying to add some client side validation with jQuery. I need something like this pseudo code: $('div').click(function(e){ if(myValidation==true){ // do nothing and let the JS in the onlick attribute do its thing } else { $error.show(); // somehow