This question already has answers here:
Click event on select option element in chrome
(13 answers)
Closed 6 years ago.
I've got the following snippet of code on my webpage:
$('#activityFilter option').on('click', function() {
var text = document.getElementById("tableFilter").value;
searchTable(opts, text);
$('.spotRow').first().click();
});
In my index.html file, there is a drop-down <select id="activityFilter">, and I'm trying to call searchTable whenever the user selects a new item on this drop-down. However, it seems like the .on('click') is never triggered in Chrome or Safari. However, it's working fine in Firefox and IE. Any suggestions?
Try to use the jQuery's click instead of attaching an event
Related
This question already has answers here:
Event binding on dynamically created elements?
(23 answers)
JavaScript does not fire after appending [duplicate]
(3 answers)
Closed 7 years ago.
Working on a poll/voting system where people can click to see results before voting, and then click back again to see the options once more.
The problem is when loading in the results, the button I load to show the options again won't seem to work:
The code for them is basically the same (I've put an alert to test if it was even picking up the button, it is not):
$('.results_button').click(function() {
var poll_id = $(this).data('poll-id');
$('.poll_content').load('/includes/ajax/poll_results.php', {'poll_id':poll_id});
});
$('.back_vote_button').click(function() {
window.alert("Test");
//var poll_id = $(this).data('poll-id');
//$('.poll_content').load('/includes/ajax/poll_options.php', {'poll_id':poll_id});
});
The actual code to the back_vote_button is this for example:
<button name="pollresults" class="back_vote_button" data-poll-id="1">Back to voting</button>
Is there something I am missing about interacting with jquery loaded content?
Is your button being created after the doc is loaded? If doesn't exist at the time that the document is created, the listener is not bound. You can either bind a listener event or you can change the click to listen to an already created object, for a bad example try this:
$(document).on('click', '.back_vote_button', function(){
window.alert("Test");
});
this should work but it will listen every time you click on the body and then determine what you clicked on if this were the problem.
This question already has answers here:
Event binding on dynamically created elements?
(23 answers)
Closed 8 years ago.
hello people here is my ajax output...
$(function(){
//after ajax request
success:function(data){
$('#inbox').html('<div class="inbox_user" id='+data+'>'+data+'</div><br>')
}
})
Div is creating successfully,so Iam very sure no issues with ajax code....but now i have to give click event to class .inbox_user ,,,its not working with no error message on console... click event for #inbox works fine..... any idea to fix this??
i am trying in normal way $('.inbox_user').click(function(){})
try this :-
$(document).on('click', '.inbox_user',function(){
alert(1);
});
Demo
This question already has answers here:
javascript or jQuery doesn't work in dynamically generated content
(4 answers)
Closed 9 years ago.
I have a Jquery script which should be fired when a file input changes. It works in a static page, but when content is generated it doesn't respond. Where is my problem?
$("#file_input").on("change", function(){
Code To Execute
});
You need to use event delegation:
$(document).on("change", "#file_input", function() {
Reason being -- these events are bound at run time. If your content isn't there at time, there's nothing to bind to! document in the above example is whatever the container is that has your appended content and also existed at run time.
This question already has answers here:
Click event on select option element in chrome
(13 answers)
Closed 9 years ago.
This code works in Firefox but not in Chrome. Alert is executed only in Firefox. Why? What am I doing wrong?
jQuery(document).ready(function($){
$('#myselect option').on('click', function() {
var selectvalue= $(this).attr('value');
alert(selectvalue);
return false;
});
});
You probably don't want to bind events to the options because the handling will be inconsistent - if someone uses the keyboard arrows to select their option, will the .click event fire?
You're probably better off just binding $('#myselect').on('change', function... which will catch any time the value is changed for any reason.
This question already has answers here:
In JavaScript can I make a "click" event fire programmatically for a file input element?
(29 answers)
Closed 9 years ago.
I get the input file element, and try to click on it in js on Chrome console, but it does not work and the file upload dialog does not appear. How can I achieve this?
document.getElementById("input_file").click();
try with onClick:
document.getElementById("input_file").onclick = function(){
//code for the action when clicked
};
Look here: http://jsfiddle.net/ghP2Y/1/