Reputation: 2437
<ul>
<li id="RadListBox1_i2" class="rlbItem ui-draggable">
<div class="ui-draggable ui-state-default" data-shortid="1007">
<em>ProductId: </em>
<span>110-01-070-10</span>
<br>
<em>ShortID: </em>
<span class="ShortID" data-shortid="1007">1007</span>
<br>
<em>Product Name: </em>
<span>Clearly Retro Style Colour Name Necklace</span>
<br>
<em>
</div>
</span>
</li>
<li id="RadListBox1_i3" class="rlbItem ui-draggable">
<li id="RadListBox1_i4" class="rlbItem ui-draggable">
</ul>
I need to build selector that find element that contains id=X and disable this item by .draggable('disable');
Some think like this:
find class y where data-shortid=X
and make it
$("ul li").find(".ShortID").attr("data-shortid="+X+).draggable('disable');
Answer :
$("span.ShortID[data-shortid="+ShortId+"]").parents("li:first").draggable("disable");
Upvotes: 2
Views: 3843
Reputation: 15603
Use this code:
$("ul li.ShortID[data-shortid="+X+"]").draggable('disable');
EDITED:
var obj = $("ul li span.ShortID");
var ids = obj.attr("data-shortid");
if(ids == X) {
obj.draggable('disable');
}
Upvotes: 1
Reputation: 45132
You need to disable the li, not the span, so you need to find the parent:
$("span.ShortID[data-shortid=1007]").parents("li").draggable("disable");
Upvotes: 2
Reputation:
$("ul li").find(".ShortID").attr("data-shortid="+X+).draggable('disable');
Would find all elements that have is inside a ul li that has a class .ShortID. To grab a element by an attribute and value. You could do
$("div[data-shortid=" + x );
Beware that in your example you have to divs with the same ID.
http://api.jquery.com/attribute-equals-selector/
Btw. Keep using find to nest deeper as in your example, this will help on performence.
Upvotes: 0
Reputation: 16871
Try this (jQuery Attribute Equals Selector):
$("ul li .ShortID[data-shortid='"+X+"']").draggable('disable');
Upvotes: 1
Reputation: 3333
$(".ShortID[data-shortid=1007]")
Above code will return you the element with class="ShortID" and attribute data-shortid="1007"
When the element is picked, you can do anything you want with it.
Upvotes: 1
Reputation: 12577
From JQuery documentation:
$( ",someclass[data-id='yourid']" ).dosomething();
Upvotes: 0