Nathan Schwarz
Nathan Schwarz

Reputation: 641

Javascript - Jquery - click(function()

Can someone tell me what is wrong with this javascript ?

      $("#parent-project").attr("data-id").click(function(){ 
       //some code...
      }

The console output is:

Cannot read property 'click' of undefined

Upvotes: 0

Views: 33

Answers (1)

AmmarCSE
AmmarCSE

Reputation: 30557

Using attr() will return a string value to which a click handler cannot be attached. I imagine you wanted

$("#parent-project[data-id]").click(function(){ 
       //some code...
      }

In which [] is notation for attribute

Upvotes: 4

Related Questions