javascript - Setting jQuery plugin options from data attributes -


im having problem setting options array value in jquery plugin using data attributes.

if reference data attribute using class selector

  $('.tm-input').tagsmanager(     {     prefilled: $('.tm-input').data('load')     }) 

it works elements same values. if reference using "this" sets correct values comes across string not array.

  $('.tm-input').tagsmanager(     {     prefilled: $(this).data('load')     }) 

i've tried using json.parse() error unexpected character. appreciated!

have tried each

$('.tm-input').each (function () {     $(this).tagsmanager( { prefilled: $(this).data('load') }); }); 

explanation:

when selector has more 1 element, applying method typically affect of elements, retrieving property typically return property 1st element.

so when use .tagsmanager on $('.tm-input') selector, applying .tagsmanger of elements. when set prefilled:$('.tm-input').data('load'), data method grabbing data first element in list, every single time.

when use each, applies logic inside of each block each element individually, rather of them @ once, when use $(this).data('load'), grabs load attribute each individual element well.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -