setting width of select (IE problem)

Discussion in 'JavaScript' started by rahulmca1@gmail.com, Jan 29, 2007.

  1. #1
    Hi,

    I am creating Html element select and setting its width using javascript
    But

    For Mozila
    var newlistOperation = document.createElement("select");
    newlistOperation.setAttribute("style", "width:191px");
    works.

    For IE
    var newlistOperation = document.createElement("select");
    newlistOperation.setAttribute("width", "191px");
    works

    I do not want to check browser type and then set width accordingly.

    How can I set width of select element so that it works for both IE as well as Mozila



    Thanks
    waiting for your response.
     
    rahulmca1@gmail.com, Jan 29, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Why not:

    
    var newlistOperation = document.createElement("select");
    newlistOperation.setAttribute("style", "width:191px");
    newlistOperation.setAttribute("width", "191px");
    
    Code (javascript):
    Mozilla will ignore the IE attribute, and IE will ignore the mozilla attribute. So simply calling both should do the trick.
     
    nico_swd, Jan 29, 2007 IP