How can I pass an argument in a function to create ID? For example in following I want ID_Name as to be taken as <div> ID. The following doesn’t work. Just to show my intention.
function create_drags(ID_Name) {
$("BODY").append($('<div ID="ID_Name" class="ui-widget-content"><p>Draggable </p></div>'));
$(ID_Name).draggable();
}
How can this be accomplished?
Updated:
Here is a working fiddle for you to try. http://jsfiddle.net/etdKL/
String concatenation.
There are two problems
The first when assigning the Id.
Instead of
ID="ID_Name"you typeID="'+ID_Name+'"Then JavaScript will evaluate ID_Name as a variable instead of a String literal.The second is that you need to use a # in the selector to tell JQuery to use the ID selector resulting in.