I’m using jQuery UI plugin for drag’n drop my object, But I have a problem.
My html Source is like this:
<html>
<body>
<div id="firstDiv">some thing is here</div>
</body>
</html>
Now, I want to draggable the above div, using helper. My code is this:
<script type="text/javascript">
$(document).ready(function(){
$("#firsstDiv").draggable({helper:anImage});
});
function anImage() {
return '<img src="~/myImage.png" alt="" />';
}
</script>
Ok, this code is work as well, but I want to set image address, But when i change my function to have a parameter, that doesnt work, O_o
My new code is this:
<script type="text/javascript">
$(document).ready(function(){
$("#firsstDiv").draggable({helper:anImage($(this).text())});
});
function anImage(address) {
return '<img src="'+address+'" alt="" />';
}
</script>
but not working.
Thanks for your helps.
OK – you can’t pass a parameter into your helper function. I’m pretty sure that’s the problem.
The way around this would be to create a setup function and then call your
anImagefunction from there:Unless of course you are trying to call
anImagewith a different image address for each draggable element, in which case the above will not work. But you shouldn’t be using the helper function to do this anyway as I’m pretty sure it’s just meant to contain code to setup all of the draggable elements you are creating.Hope this helps,
James