Very simple onclick not firing.
creating divs in a loop containing the classes:
class="person glyphicon glyphicon-user"
and i've tried selecting the class the only way i know
$('.person')click(function(){
console.log("something";
});
it just won't work, i can however print them all with the same selector, and i can fire onclick events on
$('body div').click
so its a div with class person, which leaves me clueless
thanks in advance.
edit: no browser errors, no action, nothing. the method copy pasted from my code:
$('.person').click(function() {
console.log("something");
});
You have multiple possible issues ( and assuming those are only typo's in your question):
Ensure you have jQuery added to your html file and all other jQuery usage comes after that link.
Ensure your JS is wrapped by a $(document).ready(function(){});
"creating divs in a loop containing the classes:" This leads to believe you are creating them via a JS loop? If it is then you need to call your $('.person').click(function(){});
after the loop. Creating an event on an element type ( class in this case ) does not apply to future elements.
try to use jquery on instead of click
$( ".person" ).on( "click", function() {
console.log("something");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With