How to drag a DIV if a image in it?

Discussion in 'JavaScript' started by Ginkan, Mar 20, 2010.

  1. #1
    hi,
    i want to drag the div which have a image in it:
    but i find that if i click on the image, i cannot drag the div, (in FF3.5)
    any advice would be appreciated.
    
    <div id="div1">
    <imc src="XXX.jpg">
    </div>
    
    Code (markup):
    and i have a JS something like that...:
    
    drag();
    function drag(){
    document.onmousedown = startdrag;
    document.onmouseup = enddrag;
    }
    
    function startdrag(e){
    dragobj=e.target;
    alert(dragobj.id);
    }
    ......................
    
    Code (markup):

     
    Ginkan, Mar 20, 2010 IP
  2. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    where is your drag targetted? if the drag() is in the <img>, make it refer to this.parentNode instead of this
     
    krsix, Mar 20, 2010 IP
  3. Ginkan

    Ginkan Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you sosososososo much, you are my JC!
     
    Ginkan, Mar 20, 2010 IP