Javascript equivalent of CSS border?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • effendi@epitome.com.sg

    #1

    Javascript equivalent of CSS border?

    Hi

    Can any tell me what is the javascript equivalent of CSS border? I
    would like to change the border of my cell when it is set on focus. I
    have tried onFocus="style. border='3px'" but it is not working.

    Thanks

  • Lasse Reichstein Nielsen

    #2
    Re: Javascript equivalent of CSS border?

    effendi@epitome .com.sg writes:
    [color=blue]
    > Can any tell me what is the javascript equivalent of CSS border?[/color]

    Borders are inherently presentation, and as such CSS (or old HTML).
    However, you can use Javascript to access the CSS style of an object
    through the W3C Style DOM.
    [color=blue]
    > I would like to change the border of my cell when it is set on
    > focus. I have tried onFocus="style. border='3px'" but it is not
    > working.[/color]

    Close. Try:
    onfocus="this.s tyle.border='3p x solid red';"
    or just
    onfocus="this.s tyle.borderWidt h='3px';"

    Good luck
    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Nathan

      #3
      Re: Javascript equivalent of CSS border?

      why not use the CSS pesudo-element :hover ?

      :hover works for all elements. It's only IE that refuses to handle it
      on anything other than <a>

      Comment

      • Grant Wagner

        #4
        Re: Javascript equivalent of CSS border?

        <effendi@epitom e.com.sg> wrote in message
        news:1112201805 .180329.161490@ l41g2000cwc.goo glegroups.com.. .[color=blue]
        > Hi
        >
        > Can any tell me what is the javascript equivalent of CSS border? I
        > would like to change the border of my cell when it is set on focus. I
        > have tried onFocus="style. border='3px'" but it is not working.[/color]

        I doubt you want the border turned on when the cell has the focus set on
        it (that would require the user actually click on the cell). Also,
        Gecko-based browsers and Opera have no concept of "focus" on a table
        cell:

        <table><tr><t d onfocus="alert( 'hi');">TEST</td></tr></table> does
        nothing in a Gecko-based browser or Opera, no matter how much you click
        and move the mouse around.

        So, you probably want to do this onmouseover and onmouseout (to clear
        the border when they leave the cell):

        <script type="text/javascript">
        function mOver(cell)
        {
        if (cell.style && 'undefined' != typeof cell.style.bord er)
        {
        cell.style.bord er = '3px solid Black';
        }
        }
        function mOut(cell)
        {
        if (cell.style && 'undefined' != typeof cell.style.bord er)
        {
        cell.style.bord er = 'none';
        }
        }
        </script>
        <table>
        <tr>
        <td onmouseover="mO ver(this);" onmouseout="mOu t(this);">TEST</td>
        <td onmouseover="mO ver(this);" onmouseout="mOu t(this);">TEST</td>
        <td onmouseover="mO ver(this);" onmouseout="mOu t(this);">TEST</td>
        </tr>
        </table>

        Note this creates a rather undesirable rearranging of the table as you
        move the mouse around. Personally I'd probably do something like:

        <style type="text/css">
        td { border: 3px solid White; }
        td.mOver { border: 3px solid Black; }
        </style>
        <script type="text/javascript">
        function mOver(cell)
        {
        if ('undefined' != typeof cell.className)
        {
        cell.className = 'mOver';
        }
        }
        function mOut(cell)
        {
        if ('undefined' != typeof cell.className)
        {
        cell.className = '';
        }
        }
        </script>
        <table>
        <tr>
        <td onmouseover="mO ver(this);" onmouseout="mOu t(this);">TEST</td>
        <td onmouseover="mO ver(this);" onmouseout="mOu t(this);">TEST</td>
        <td onmouseover="mO ver(this);" onmouseout="mOu t(this);">TEST</td>
        </tr>
        </table>

        Of course, in browsers that support it (Gecko-based browsers, Opera),
        all this can be replaced by:

        <style type="text/css">
        td { border: 3px solid White; }
        td:hover { border: 3px solid Black; }
        </style>
        <table>
        <tr>
        <td>TEST</td><td>TEST</td><td>TEST</td>
        </tr>
        </table>

        --
        Grant Wagner <gwagner@agrico reunited.com>
        comp.lang.javas cript FAQ - http://jibbering.com/faq


        Comment

        Working...