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!

EricBellDesigns
  • 955
  • 1
  • 9
  • 33

1 Answers1

4

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

$("div[data-for='product-description']").on("click",function() {
   alert("test click");
});
guest271314
  • 1
  • 15
  • 104
  • 177
  • 1
    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. – EricBellDesigns Dec 19 '15 at 00:23