Such a problem:

by id_ = $(ui.draggable).attr("id");

I recognize the id item being copied. I am writing a condition if (id_ == "drag1"){console.log("это объект drag1"); } if (id_ == "drag1"){console.log("это объект drag1"); } .

but this condition does not work, what's the problem?

Closed due to the fact that off-topic participants Grundy , aleksandr barakin , Alexey Shimansky , VenZell , fori1ton Apr 25 '16 at 15:17 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reasons:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - aleksandr barakin, fori1ton
  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Alexey Shimansky, VenZell
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • It depends on what $ (ui.draggable) .attr ("id") is. HTML code of the example add to the question? - Vasily Barbashev
  • and add a description of what ui , ui.draggable is - Grundy

2 answers 2

The problem was that I used the jsPlumb plugin, and the code for the entire program started with jsPlumb.ready(function() { ... });
Just changed it to $(document).ready(function(){ ... });

A working example:

 $(document).ready(function() { $(".item").draggable({ helper: 'clone' }); $("#artCanvas").droppable({ accept: ".item", drop: function(event, ui) { var id_ = $(ui.draggable).attr("id"); console.log(id_); if (id_ == "drag1") { alert(" это drag1"); } var www = $(ui.helper).clone().removeClass('objectDrag'); www.draggable(); $(this).append(www); www.draggable({ containment: 'parent' }); } }); }); 
 .objectDrag {} #artCanvas { background-image: url("https://sivers.org/images/blank.jpg"); background-repeat: no-repeat; width: 500px; height: 451px; color: white; } 
 <div class="container"> <div id="content" class="row"> <div class="objectDrag"> <img id="drag1" class="item" src="http://www.drupal.ru/files/imagecache/96x96/pictures/picture-41225.jpg"> <img id="drag2" class="item" src="http://www.vista-style-icons.com/libs/smile/indifference-icon.gif" /> </div> <br> <div id="artCanvas"></div> </div> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="//ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/jquery-ui.min.js"></script> <link rel="stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/themes/sunny/jquery-ui.css"> 

  • It is worth adding an explanation of what exactly did not work and how it was fixed - Grundy
  • The problem was that I used the jsPlumb plugin and the code for the entire program started with jsPlumb.ready (function () {}); Just changed it to $ (document) .ready (function () {}); - Svetlana

This condition does not work, because id_ not equal to "drag1"

  • I have several objects that I can copy. id of each element = drag1, drag2, etc. that's it, when I copy the element with id = drag1 it should be displayed that this is a drag1 object - Svetlana
  • @ Svetlana, it means that you are copying not drag1 :-) judging by the code provided - the id value is not equal to drag1 for this condition does not work. - Grundy
  • I will try to make an example) seriously, this can be a mistake - Svetlana
  • I found my mistake, thank you) Everything works correctly, just denver is buggy) - Svetlana
  • @ Svetlana, and what was it? :) - Grundy