This task has been canceled!

0

Created by
pond87 52 about 24 days ago

jQuery Object / data attribute access issue

I am trying to troubleshoot some jQuery code and added this:

alert(this.dragEl.data('type'));

and all the alert returns is undefined. So I try this:

alert(this.dragEl.html());

and I get the expected DOM element in the alert

<li class="dd-item dd3-item" data-type="parent" data-id="6" data-new_record="false">
...
</li>

I am no JS or jQuery expert by any means and I am at a loss why I can't get the parent data value from this.

UPDATE

Did some digging to find where this is set:

this.dragEl = $(document.createElement(this.options.listNodeName)).addClass(this.options.listClass + ' ' + this.options.dragClass);

For context this is the Nestable2 (https://github.com/RamonSmit/Nestable2) plugin. The li is cloned then destroyed from the DOM. The user is now dragging this around to drop on a new home location. I am trying to add some user feedback so that when you try and drop this on a 'not allowed' location the default blue placeholder dropzone div that gets added is red. It seems to be an easy patch once I figure out how to read that data attribute on the item being moved.

Added the code in question to a JS fiddle (line 1041):

https://jsfiddle.net/jasper502/jzaqvsbp/

See task infos

Solutions (1)

0

ourjourney 64 about 21 days ago
10 mBCH
Accepted solution