change style of cursor for textarea

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dineshkumarsr
    New Member
    • Jan 2008
    • 3

    change style of cursor for textarea

    Hi Folks,
    I have a issue trying to change the cursor of area image map in run time, no static code, no id and no name.

    the possibilities i have tried is

    [CODE=javascript]document.getEle mentsByTagName( "area").style.c ursor=hand;
    var cur=document.ge tElementsByTagN ame("area");
    cur..style.curs or=hand;[/CODE]

    not working
    -----------------------------------------------------------------------------
    [CODE=javascript]function winload()
    {

    var areatg=document .getElementsByT agName("AREA");
    for(k=0;k<areat g.length;k++)
    {
    areatg[k].setAttribute(" href","#");
    }
    }
    window.onload=w inload;[/CODE]

    this is working only one time onload only.

    tried with setTimeout, setInterval onmouseover.

    not working
    -------------------------------------------------------------

    Please send me your valuable useful suggestions As soon as possible

    Cheers,
    Dinesh
    Last edited by gits; Jan 18 '08, 12:07 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    welcome to TSDN ...

    first: please use a meaningful title for your thread and use code-tags when posting source-code ... read the posting guidelines

    second: to your problem ... you could use the getElementsByTa gName()-method but you should know, that this function returns a node-list (list of elements with the specified tagname) ... so you have to refer to the element with the correct index in the retrieved list. assuming you only have one textarea in your page you could use the following statement:

    [CODE=javascript]document.getEle mentsByTagName( 'textarea')[0].style.cursor = 'hand';
    [/CODE]
    kind regards

    Comment

    • dineshkumarsr
      New Member
      • Jan 2008
      • 3

      #3
      Thanks for replying to my issue. As per your suggestion, I have tried this but not working, can think for better solution.

      [CODE=javascript]function changeLink()
      {
      var arealen=documen t.getElementsBy TagName('area') ;
      for(i=0;i<areal en.length;i++)
      {
      document.getEle mentsByTagName( 'area')[i].style.cursor = 'hand';
      }
      }
      [/CODE]
      cheers,
      dinesh
      Last edited by gits; Jan 19 '08, 04:51 PM. Reason: added code tags

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        Originally posted by dineshkumarsr
        Thanks for replying to my issue. As per your suggestion, I have tried this but not working, can think for better solution.

        [CODE=javascript]function changeLink()
        {
        var arealen=documen t.getElementsBy TagName('area') ;
        for(i=0;i<areal en.length;i++)
        {
        document.getEle mentsByTagName( 'area')[i].style.cursor = 'hand';
        }
        }
        [/CODE]
        cheers,
        dinesh
        does that work? the tagName should be textarea ... isn't it? and it is a better idea to store the reference once you have retrieved the nodelist ... since all dom-methods are expensive in terms of runtime-performance ... so avoid it when possible:

        [CODE=javascript]function changeLink() {
        var areas = document.getEle mentsByTagName( 'textarea');
        var arealen = areas.length;

        for (i = 0; i < arealen; i++) {
        areas[i].style.cursor = 'hand';
        }
        }[/CODE]
        kind regards

        ps: in FF & mac i just tested the 'hand' cursor that didn't work while the 'pointer' cursor did :)

        Comment

        • jerone
          New Member
          • Nov 2007
          • 2

          #5
          I'm having the same issue today.
          The topicstarter does mean area (used for image maps).
          [CODE=javascript]areas = document.getEle mentsByTagName( 'area');
          for(var a=0;a<areas.len gth; a++){
          areas[a].style.cursor = "help";
          }[/CODE]
          I've tested it in FF and it works, but it doesn't work in Opera and IE.
          Anyone got another solution.

          gr J

          Comment

          • pronerd
            Recognized Expert Contributor
            • Nov 2006
            • 392

            #6
            It is a better convention in JavaScript to use single quotes in JavaScript that double. How many area tags do you have in your page? Can you post the code from the page?

            Comment

            Working...