javascript-events interview questions
Top javascript-events frequently asked interview questions
I'm trying to show up a container if a input field gets the focus and - that's the actual problem - hide the container if focus is lost. Is there an opposite event for jQuery's focus?
Some example code:
<input type="text" value="" name="filter" id="filter"/>
<div id="options">some cool options</div>
<script type="text/javascript">
$('#options').hide();
$('#filter').focus(function() {
$('#options').appear();
});
</script>
And what I'd like to do is something like this:
$('#filter').focus_lost(function() {
$('#options').hide();
});
Source: (StackOverflow)
I'm attempting to capture mouse events on an element with another absolutely-positioned element on top of it.
Right now, events on the absolutely-positioned element hit it and bubble up to its parent, but I want it to be "transparent" to these mouse events and forward them on to whatever is behind it. How should I implement this?
Source: (StackOverflow)
This question already has an answer here:
Is there a way to check if an event exists in jQuery? I'm working on a plugin that uses custom namespaced events, and would like to be able to check if the event is binded to an element or not.
Source: (StackOverflow)
Is it possible to have an event that fires when the value of a certain variable changes?
Thanks!
Source: (StackOverflow)
I have a form
with two text boxes, one select drop down and one radio button. When the enter key is pressed, I want to call a javascript function (User defined), but when I press it, the form is submitted.
How do I prevent the form
from being submitted when the enter key is pressed?
Source: (StackOverflow)
How do you obtain the clicked mouse button using jQuery?
$('div').bind('click', function(){
alert('clicked');
});
this is triggered by both right and left click, what is the way of being able to catch right mouse click? I'd be happy if something like below exists:
$('div').bind('rightclick', function(){
alert('right mouse button is pressed');
});
Source: (StackOverflow)
What is the difference between event bubbling and capturing? Of the two, which is the faster and better model to use?
Source: (StackOverflow)
I am using Ajax and hash for navigation. Is there a way to check if the window.location.hash
changed like this?
http://example.com/blah#123 to http://example.com/blah#456
It works if I check it when the document loads.
But if I have #hash based navigation it doesn't work when I press the back button on the browser (so I jump from blah#456 to blah#123). It shows inside the address box, but I can't catch it with JavaScript.
Source: (StackOverflow)
I have attached an event to a text box using addEventListener
. It works fine. My problem arose when I wanted to trigger the event programmatically from another function.
How can I do it?
Source: (StackOverflow)
If there is an Javascript object:
var objects={...};
Suppose, it has more than 50 properties, without knowing the property names (that's without knowing the 'keys') how to get each property value in a loop?
Source: (StackOverflow)
I would like to detect whether the user has pressed Enter
using jQuery.
How is this possible? Does it require a plugin?
EDIT: It looks like I need to use the keypress()
method.
I wanted to know if anyone knows if there are browser issues with that command - like are there any browser compatibility issues I should know about?
Source: (StackOverflow)
how could I fire a event if the a css class was added or changed with jQuery?
Does changing of CSS class fire the jQuery change() event?
Source: (StackOverflow)