Reputation:
I have the following HTML:
<div class="button disabled dialogLink"
id="edit"
data-action="Edit" >
<div class="sprite-blank" ></div>
</div>
This javascript
$('.dialogLink')
.click(function () {
adminDialog(this);
return false;
});
function adminDialog($link) {
"use strict";
link = {
action: $link.data('action') || ''
I get an error saying
Uncaught TypeError: Object #<HTMLDivElement> has no method 'data'
Does anyone have an idea what I am doing wrong. It seems very simple code so I can't understand what's wrong.
Upvotes: 2
Views: 1116
Reputation: 144739
You should first create a jQuery object for using jQuery object's methods like data
method. You can use dataset
object:
$link.dataset.action
or jQuery data
method:
$($link).data('action')
Upvotes: 3