2

Hi am attempting to fire off some jQuery on the click event of a div. I am attempting to target the element via jQuery's attribute equals selector, but I have not had any luck so far. I've used this selector several times in the past, but never with a custom attribute. It seems unlikely that a custom attribute would cause an issue with using this method to me, but maybe I'm wrong. Anyway here is the code I am using:

$( "div[data-for='product-description']" ).live("click", function({
	alert("test click");
}));
<div class="m-pageEl ui-collapsible" data-for="product-description"><a href="#"><span class="ui-btn-txt">Description</span><span class="caret pull-right"></span></a></div>

I do not receive any console errors, so I'm not sure what the issue could be here, but my alert never fires on click. I have tried using .click and .live("click"... If anyone has a suggestion, it would be greatly appreciated!

1 Answer 1

4

The jquery code should be like below then it will work...

$("div[data-for='product-description']").on("click",function() {
   alert("test click");
});
Sign up to request clarification or add additional context in comments.

1 Comment

Ah sorry Karthik, my problem was actually a missing reference to jQuery in my jsFiddle and code snippet. My code as well as your code works correctly. I am deleting the question because this was an error on my part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.