views:

33

answers:

3

Hello

I've the following element

<div class="class1 class2 class3"></div>

I'm trying to get all the elements with class name 'class3' using jquery

$('.class3').droppable();

But i'm not getting the above div as droppable. Any ideas?

+2  A: 

Edit for updated question:

.droppable() doesn't take a function, it takes an object or nothing, you just need this for the defaults:

$('.class3').droppable();

Also make sure it's in a document.ready handler, like this:

$(function() {
  $('.class3').droppable();
});

Then, also make sure jQuery UI is included correctly in your page...you should be getting an error if this isn't the case (.droppable() isn't a function, etc).

Nick Craver
Sorry. I've updated the post.
NLV
@NLV - Updated the answer to match :)
Nick Craver
Thanks! I know droppable() doesn't take a function. Forgot to edit that part :). I've put that inside $(document).ready() but i still dont see it as droppable.
NLV
I dont see ui-droppable class applied to my div element.
NLV
@NLV - You should be getting an error then, if you're not do a `alert($('.class3').length);` in that same `ready` handler to see how many elements it's matching.
Nick Craver
I'm getting 0. Okie i got it. I create the elements dynamically in code behind on user interactions. So document.ready() which is called initially cant find any elements with that class. Will change the logic. Thanks for your help :).
NLV
@NLV - Welcome :) as a tip be sure to include that dynamic part in future questions, will get us on the right track much faster...completely different approach in those cases :)
Nick Craver
Sure. I'm still not getting it. I'll create it as a separate question.
NLV
A: 

Try this

    $('.class3').droppable({ accept: 'someselector' });
JapanPro
You should never needs to do this, also `.droppable()` still doesn't take a function.
Nick Craver
thats correct nick, i was taking it as custom function, but thats correct what you are saying.
JapanPro
@JapanPro - There's still no need for a `.each()` here :)
Nick Craver
i have each coz before post was updated it was showing each issue, so i have to reside as soon as i change , post updated as per that. thanks for your input.
JapanPro
+1  A: 

That should work for sure, here are some other potential causes of your error:

Executed before DOM is ready Make sure your code is executed after the DOM has been loaded

$(document).ready( function() {
    //Your Code
});

$ object conflicting Several objects make use of the variable $ as shorthand for their functions, try using jQuery. instead.

jQuery(document).ready( function() {
    jQuery('.class3').each(function(){
    });
});

Edit for updated question I'm not well versed with the droppable plugin, but the jQuery website has an example which looks like this:

$("#droppable").droppable({
  drop: function() { alert('dropped'); }
});

More Info: http://docs.jquery.com/UI/Droppable

Andrew Dunn