Is there any way to detect click event #49
-
There is a way to detect change event
But when i tried click event
It does not work . is there any way to detect click event ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
@ajit-soman code you have mentioned would work if this code is present after virtual select initialized. VirtualSelect.init({
ele: '#sample-select',
...
});
$('#sample-select').click(function () {
console.log(this.value);
}); Alternatively, you could use the below code to add a listener before initialization. $(document).on('click', '#sample-select', function () {
console.log(this.value);
}); |
Beta Was this translation helpful? Give feedback.
-
I have encountered the same problem.. somehow.. Original question was "Is there a way to detect change". Because it can be changed programmatically, not by a click event only, or by keyboard. And Here is what I do: MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
function observeChange (element) {
var observer;
observer = new MutationObserver(function(mutations, observer) {
if(mutations[0].attributeName === "value") {
$(element).trigger("change");
}
});
observer.observe(element, {
attributes: true
});
}
// Register to observe changes in this element...
observeChange($("#myDropdown")[0]);
// Now can detect change
$("#myDropdown").on("change", function (e) {
console.log($(this).val());
}); |
Beta Was this translation helpful? Give feedback.
@ajit-soman code you have mentioned would work if this code is present after virtual select initialized.
Alternatively, you could use the below code to add a listener before initialization.