Try:
$("p span.text").on('click', function(){
console.log('I was clicked');
});
Question
How do I bind 'click' to a paragraph?
I have the following function:
$(document).on('touchstart mousedown',"p span.text", function(e) {
console.log('I was clicked');
*more code here*
});
If I replace 'touchstart mousedown' with 'click', the function is no longer fired.
PS: I'm SUPER new to JS, so I might be doing something wrong.
La solution
Try:
$("p span.text").on('click', function(){
console.log('I was clicked');
});
Autres conseils
How do I bind 'click' to a paragraph
Try to attach click
event to your paragraph instead of span
:
$(document).on('touchstart mousedown click',"p", function(e) {
console.log('I was clicked');
});
This also works: According to your reply, updated
$(document).on('click',"p span", function(e) {
console.log('I was clicked');
});