Changing the cursor dynamically using JavaScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guilherme21922
    New Member
    • Jan 2008
    • 28

    Changing the cursor dynamically using JavaScript

    I have a figure SVG, and i´m trying to on mouseover event, change the cursor style to "hand".

    I tried to do this:

    var figure= document.embeds['SVG'].getSVGDocument ().getElementBy Id(elementId);

    figure.style.cu rsor = "hand";

    thanks for the help
  • clivethebadger
    New Member
    • Feb 2008
    • 12

    #2
    Try using the keyword 'pointer' instead of 'hand'. This is supposed to be the standard and should work on most browser.

    Jon

    Comment

    • guilherme21922
      New Member
      • Jan 2008
      • 28

      #3
      it doesn´t work...
      and the strange thing is that nothing happens...
      no error...and no ...pointer or hand

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        What's elementid? Which element are you referring to?

        Comment

        • guilherme21922
          New Member
          • Jan 2008
          • 28

          #5
          elementid refers to the id of the element
          and the element is a rect

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            I think you may need the root element before calling getElementById as described here.

            If that doesn't work, show the corresponding HTML code.

            Comment

            • guilherme21922
              New Member
              • Jan 2008
              • 28

              #7
              Here is a description of the SVG file:

              [HTML]<svg xmlns="http://www.w3.org/2000/svg"
              xmlns:xlink="ht tp://www.w3.org/1999/xlink"
              version="1.1"
              baseProfile="fu ll"
              id="SVG" image-rendering="opti mizeSpeed" width="612" height="800"
              viewBox="0 0 612 792" overflow="visib le" enable-background="new 0 0 612 792" onload="initSVG ()">

              <rect id="Planta" x="-70.0" y="60.5" fill="#FFFFFF" width="710" height="655" onclick="onClic k(evt)"/>
              <g id="Group">
              <g id="SmallGroup " onmouseover="Ch angeColor(evt)" fill="lightgrey ">
              <rect id="idRect" name="FigureNam e" x="408" y="154" fill="silver" width="97" height="5"/>
              </g>
              </g>
              </svg>
              [/HTML]

              And here is a description of javascript file:

              [CODE=javascript]function ChangeColor(evt )
              {
              var elementId = evt.target.getI d();
              var figure = document.embeds['SVG'].getSVGDocument ().getElementBy Id(elementId);
              figure.setAttri bute("opacity", 0.25);

              }[/CODE]
              Last edited by acoder; Feb 26 '08, 10:55 AM. Reason: Added code tags

              Comment

              • guilherme21922
                New Member
                • Jan 2008
                • 28

                #8
                And the opacity works...
                So i just want to know how i change the mouse style to "hand" when i pass the mouse over the "rect".

                Thanks

                Comment

                • guilherme21922
                  New Member
                  • Jan 2008
                  • 28

                  #9
                  where obj = figura in my code;

                  i have done that...

                  figura.style.cu rsor = 'pointer';


                  and nothing happens...no error and no hand...

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5388

                    #10
                    Originally posted by guilherme21922
                    where obj = figura in my code;

                    i have done that...

                    figura.style.cu rsor = 'pointer';


                    and nothing happens...no error and no hand...
                    just to ensure - i only see figure and no figura in your script?

                    Comment

                    • guilherme21922
                      New Member
                      • Jan 2008
                      • 28

                      #11
                      ok...i have typed wrong here

                      where obj = figure in my code;

                      i have done that...

                      figure.style.cu rsor = 'pointer';

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Try using setAttribute to set the cursor.

                        Comment

                        Working...