behrouz vb
behrouz vb

Reputation: 1

How can i reference to element which calls a jQuery plugin?

For example:

<div id="target" data-width="400px"></div>

$("#target").myPlugin({width: ??? });

??? must be data-width attribute value.

Upvotes: 0

Views: 47

Answers (3)

NullPoiиteя
NullPoiиteя

Reputation: 57312

you can do this by

$("#target").myPlugin({
  width: $("#target").data('width') 
 });

all credit goes to adeneo

Upvotes: 1

Ravi Y
Ravi Y

Reputation: 4376

$("#target").myPlugin({width: $("#target").attr('data-width') });

Upvotes: 1

Ajouve
Ajouve

Reputation: 10089

http://api.jquery.com/width/

You can easyly get leh width with .width()

Upvotes: 0

Related Questions