onClick not working on mobile (touch)

better to use touchstart event with .on() jQuery method: $(window).load(function() { // better to use $(document).ready(function(){ $(‘.List li’).on(‘click touchstart’, function() { $(‘.Div’).slideDown(‘500′); }); }); And i don’t understand why you are using $(window).load() method because it waits for everything on a page to be loaded, this tend to be slow, while you can use $(document).ready() … Read more

How to have click event ONLY fire on parent DIV, not children?

If the e.target is the same element as this, you’ve not clicked on a descendant. $(‘.foobar’).on(‘click’, function(e) { if (e.target !== this) return; alert( ‘clicked the foobar’ ); }); .foobar { padding: 20px; background: yellow; } span { background: blue; color: white; padding: 8px; } <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js”></script> <div class=”foobar”> .foobar (alert) <span>child (no alert)</span> </div>

How to add click event to a iframe with JQuery

There’s no ‘onclick’ event for an iframe, but you can try to catch the click event of the document in the iframe: document.getElementById(“iframe_id”).contentWindow.document.body.onclick = function() { alert(“iframe clicked”); } EDIT Though this doesn’t solve your cross site problem, FYI jQuery has been updated to play well with iFrames: $(‘#iframe_id’).on(‘click’, function(event) { }); Update 1/2015 The … Read more

Uncaught ReferenceError: function is not defined with onclick

Never use .onclick(), or similar attributes from a userscript! (It’s also poor practice in a regular web page). The reason is that userscripts operate in a sandbox (“isolated world”), and onclick operates in the target-page scope and cannot see any functions your script creates. Always use addEventListener()Doc (or an equivalent library function, like jQuery .on()). … Read more

Execute PHP function with onclick

First, understand that you have three languages working together: PHP: It only runs by the server and responds to requests like clicking on a link (GET) or submitting a form (POST). HTML & JavaScript: It only runs in someone’s browser (excluding NodeJS). I’m assuming your file looks something like: <!DOCTYPE HTML> <html> <?php function runMyFunction() … Read more

How to switch to new window in Selenium for Python?

You can do it by using window_handles and switch_to.window method. Before clicking the link first store the window handle as window_before = driver.window_handles[0] after clicking the link store the window handle of newly opened window as window_after = driver.window_handles[1] then execute the switch to window method to move to newly opened window driver.switch_to.window(window_after) and similarly … Read more