문제

Hi following is my code Snippet. What i am trying to do is that i want to find img within the image_div and attach draggable event to it.

    $(function() {
        jQuery('#image_div').each({
       $(this).find('img').draggable({revert: true});)};
    });

Above Code Throws me following error

SyntaxError: missing : after property id//$(this).find('img').draggable({revert: true});
도움이 되었습니까?

해결책

you're overcomplicating it..

Here is your updated fiddle.. http://jsfiddle.net/jFIT/FCjr5/1/

Selectors in JQuery always return an array of objects. you do not need to use a loop to iterate through them to create events for each one.. for example, 5 buttons with the same class "buttonClass" have the same click event: $('.buttonClass').click(function () { ..... });

다른 팁

You're calling .each() on a single element. Your selector $('#image_div'); will return the one div element. Use .find() directly on this element to look within it and find all img tags. Your code should look like this.

$(function() {
    jQuery('#image_div').find('img').draggable({ revert: true });
});

Also in your fiddle, your img tags weren't closed and you need to reference jQuery ui on the left hand side for .draggable() to work

Here is a working fiddle.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top