I'm stuck with a concept, not sure if my logic is right, it most likely isn't.
I'm hoping to achieve a div delete. So I click the div and it makes it the active div and then I can delete it with the backspace key.
So the flow is -. Click Element - Hit Backspace - $(this).remove();,
but not sure how to target the element with a click. I had:
$(".spike").live(event, function(del) {
if (del.keyCode == 8) { $(this).remove();}
});
but it doesn't work. (The event is bound to click and ipad touch).
Basically is there any way I can use the click event to target a div, maybe to a global variable, that then allows me perform actions to it?
Well the idea is to select an item, and save the selection. Then if the key you want is pressed, delete that item.
Look at this example:
http://jsfiddle.net/GVgEy/5/
change "event" for "click" which is the event you want to handle.
$(".spike").live("click", function(del) {
if (del.keyCode == 8) { $(this).remove();}
});
Hm... I have little to offer but a demo http://jsfiddle.net/E8RaX/1
but the idea is that you assign a class to the active object and then with some prevent defaults you remove any divs with that class.
Related
Trying to have it so when a link is clicked aside one input, it will hide that link and focus to the input field in the next div. I need to reference it with an event-target for other reasons.
If I change .focus(); to .val('blah'); it works, and other, more typical methods i.e. $('a').click(function() {... will do the job. Is this just a limitation of using event-target?
Here is a fiddle
Your mousedown event does'nt trigger the handler, you'll need to use click() instead.
Something like this FIDDLE
I'm designing a webpage where I have a combobox (drop down list) and it has several items in it. I want to be able to click the element and select the first item and it should fire the changed event.
Initial situation:
I will click the button next to 1/2000 and:
Afterwards, if I click on 1/2000, I want the changed event to fire. I know it is simple with jQuery, but I couldn't find how to search for this problem so couldn't find an answer.
Thanks, Can.
I think James is right, the question is not how to simply detect a change, he rather wants to know detect the click.
You could use this code but you need to find a way to make it not fire twice if another option is selected:
$('select option').click(function(){
$(this).parent('select').trigger('change');
});
$('select').change(function(){
alert("Bam!");
});
The event is fired when you select the option, if you want to do something when it's fgired you should do:
$('#yourselect').change(function(){
alert('changed');
});
Look at this fiddle:
http://jsfiddle.net/5wc37/
EDIT - tanks to james now i understand what the poster want. One thing you coukd do is binding the click event to the select and check if the target is an option or a select. if it's an option, do what you want:
$('select#yourselect').click(function(e) {
if(e.target.tagName === "OPTION"){
alert(this.value);
};
});
fiddle
http://jsfiddle.net/5wc37/12/
I need to detect keystroke combinations in one active (focused) element. However when I have focus on another element and the same keystrokes are pressed, the action shouldn't be fired.
I seem to have trouble doing this. Any help will be appreciated.
Thanks.
You could check out my jQuery plugin that would allow you to do this by selecting the element then picking the key like:
$('input').jkey('alt+a',function(){
console.log('You pressed alt+a!');
})
Docs:
http://oscargodson.com/labs/jkey/
Source:
https://github.com/oscargodson/jkey
I have a DataTable in YUI. I'm trying to get the table to ignore all keyEvents. I've tried these methods:
YAHOO.util.Event.addListener(singleSelectDataTable, "keydown", function(oEvent) {
YAHOO.util.Event.stopPropagation(oEvent);
});
OR
YAHOO.util.Event.preventDefault(singleSelectDataTable.tableKeyEvent);
OR
singleSelectDataTable.subscribe('tableKeyEvent', function(oArgs) {
YAHOO.util.Event.preventDefault(oArgs.event);
});
I've looked at a couple of YUI examples to intercept click events, but they don't analogize to this specific scenario. I created a standalone HTML test file if that will help: http://pastebin.com/khfR4Stk. The foundational problem is that we don't want to support arrow key up or arrow key down in our tables; it's a scrolling table and in order for it to work properly we would have to adjust the scrolling thumb once the selection goes past the 'shown-window'.
The only other solution I could think of is to subscribe to the tableKeyEvent and then if the keypress is up-arrow, then unselect the newly selected row, selecting the previous row, doing the appropriate analogue for a down-arrow (basically undoing what the keypress just did). This didn't seem like the right solution…
The tableKeyEvent is raised after the up/down arrow key has been handled. So trying to stop that event will not help.
Looking at the _onTbodyKeydown function of the DataTable widget, I noticed that setting the selection mode to an invalid mode disables key arrow key navigation. Luckily it doesn't seem to break the other selection handling. At least not in your example.
So just change selectionMode:"single" to selectionMode:"" and you should be fine :-)
(Of course there is no guarantee that this will work in future versions)
Try creating the equiv of this onclick
function noenter(evt)
{
var k = evt.keyCode||evt.which;
return k != 13;
}
Get the syntax for getCharCode and tell the script that when it receives input, it needs to deny it.
can't you just add an eventhandler that returns false to the keydown event?
I'm not sure if this is even possible, but I figured I'd ask before clubbing togehter an ugly solution.
What I have is a group of radio buttons and I want to trigger a function if the radio button value is changed. For example say there are three buttons X Y and Z with Y default selected. If a user clicks on an unselected button (i.e. X or Z) then the function gets triggered but if he/she clicks on Y (which is already selected) nothing happens.
Naturally the best solution would be to fire the function on an onchange event but IE6 doesn't fire onchange until the focus is no longer on the element which is not satisfactory.
So is there a way to know what the previous value of the radio button was or at least what its default value is? I could easily create an array of default values and check against that but I'm trying to reduce the overhead.
Please no jQuery suggestions ;)
Use the defaultChecked property of the input element.
You could also use the click event for this, because click event fires also when the user uses the spacebar/enter key on it to "check" it.
Well, you could use the onmousedown event on the input elements. It would do what you're asking (activate an event when the user clicks), but with onmousedown, you can check if the element was already selected. Example:
document.getElementById('#radio-button-x').onmousedown = function() {
if (this.checked == true) {
// was already selected
} else {
// not selected, do something
}
};