I want to get the id of the div i am moving. I have tried different methods, nothing worked. So why isn't this working?
$('#content').children().draggable({
drag: function (event, ui) {
var id = $(this).attr("id");
$('#textarea').val(id);
}
I want to get the id of the div i am moving. I have tried different methods, nothing worked. So why isn't this working?
$('#content').children().draggable({
drag: function (event, ui) {
var id = $(this).attr("id");
$('#textarea').val(id);
}
This doesn't work because you are not finding the id of $('#content')
, but of the child div, which does not have an id set. Thus, give the child an ID and it will find that one.
It's because $(this) is refering to the inner div marked with the class
see http://jsfiddle.net/pX2T4/
<div id="content">
<div class="content" id="foo">
<textarea name="" id="textarea" cols="30" rows="10"></textarea>
</div>
</div>
$('#content').children().draggable({
drag: function (event, ui) {
var id = $(this).attr("id");
console.log(id);
console.log($(this));
$('#textarea').val(id);
}
});
outputs "foo"