Adding Events to newly created controls question...

Discussion in 'Javascript' started by xxbmichae1@supergambler.com, Nov 6, 2005.

  1. Guest

    I'm having a hard time getting this code to work...the onMouseOver and
    onMouseOut events don't seem to be firing in IE or Mozilla.....thanks
    in advance for any assistance...

    var imgf = document.createElement("img");
    imgf.src = "../files/img.gif";
    imgf.style.cursor = "pointer";
    imgf.style.border = "1px solid blue";
    imgf.title = "Date selector";

    // below is not working at all......

    imgf.onMouseOver = "this.style.background='blue';";
    imgf.onMouseOver = "this.style.background='';";


    Thanks again!

    Michael
    , Nov 6, 2005
    #1
    1. Advertising

  2. Mick White Guest

    wrote:

    > I'm having a hard time getting this code to work...the onMouseOver and
    > onMouseOut events don't seem to be firing in IE or Mozilla.....thanks
    > in advance for any assistance...
    >
    > var imgf = document.createElement("img");
    > imgf.src = "../files/img.gif";
    > imgf.style.cursor = "pointer";
    > imgf.style.border = "1px solid blue";
    > imgf.title = "Date selector";
    >
    > // below is not working at all......
    >
    > imgf.onMouseOver = "this.style.background='blue';";
    > imgf.onMouseOver = "this.style.background='';";
    >

    imgf.onmouseover = function(){this.style.backgroundColor='blue';}

    Mick
    Mick White, Nov 6, 2005
    #2
    1. Advertising

  3. Guest

    Thanks you very much.....looked all over the place for this....is there
    a good DOM reference book you know of?? or where info like this is
    located?

    Thanks again!
    , Nov 6, 2005
    #3
  4. Mick White Guest

    Mick White wrote:

    >>

    > imgf.onmouseover = function(){this.style.backgroundColor='blue';}
    >



    Oops, makes no sense to assign a background colour to an image

    imgf.onmouseover = function(){this.parentNode.style.backgroundColor='blue';}

    Mick
    Mick White, Nov 6, 2005
    #4
  5. Mick White Guest

    Mick White, Nov 6, 2005
    #5
  6. Mick White Guest

    Mick White wrote:

    > Mick White wrote:
    >
    >>>

    >> imgf.onmouseover = function(){this.style.backgroundColor='blue';}
    >>

    >
    >
    > Oops, makes no sense to assign a background colour to an image
    >
    > imgf.onmouseover =
    > function(){this.parentNode.style.backgroundColor='blue';}
    >

    Caveat: The image needs to be appended to its parent before you may
    reference the parentNode.
    Mick
    Mick White, Nov 6, 2005
    #6
  7. Guest

    Thanks Mick.....you seem very knowledgable on these things, mind if I
    ask you another question.....

    I'm trying to set the class of a newly created object

    I've tried the following two statements...

    imgf.class = "classname";
    imgf.style.class = "classname";

    This doesn't seem to work, it causes a JavaScript error message......do
    you know the correct syntax?

    Thanks

    Michael
    , Nov 8, 2005
    #7
  8. web.dev Guest

    wrote:
    > Thanks Mick.....you seem very knowledgable on these things, mind if I
    > ask you another question.....
    >
    > I'm trying to set the class of a newly created object
    >
    > I've tried the following two statements...
    >
    > imgf.class = "classname";
    > imgf.style.class = "classname";


    Correct syntax is as follows:

    imgf.className = "classname";

    >
    > This doesn't seem to work, it causes a JavaScript error message......do
    > you know the correct syntax?
    >
    > Thanks
    >
    > Michael
    web.dev, Nov 8, 2005
    #8
  9. wrote:

    > I'm trying to set the class of a newly created object
    >
    > I've tried the following two statements...
    >
    > imgf.class = "classname";
    > imgf.style.class = "classname";
    >
    > This doesn't seem to work, it causes a JavaScript error message......


    "a JavaScript error message" is as bad an error description as any.

    > do you know the correct syntax?


    <FAQENTRY>

    Since `class' is a reserved word in several interfacing languages,
    including JS/ECMAScript, it cannot be used for identifiers which is
    why the DOM Level 2 HTML ECMAScript binding specifies the `class'
    attribute of HTML elements to be accessible through the implemented
    `className' attribute of HTMLElement objects.

    imgf.className = "classname";

    See <http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-213157251>.

    </FAQENTRY>

    BTW, that is a FAQ here; not covered by the FAQ list[1] yet, however it can
    be searched through (Google Groups) archives which is the first thing one
    should do before posting.

    <http://jibbering.com/faq/#FAQ2_11>


    PointedEars
    ___________
    [1] <http://jibbering.com/faq/>
    Thomas 'PointedEars' Lahn, Nov 8, 2005
    #9
  10. Guest

    thanks!
    , Nov 8, 2005
    #10
  11. Guest

    Thanks Thomas, I tried searching first and came up with nothing
    useful....I'll search the link you provided first next time.
    , Nov 8, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl Teigrob
    Replies:
    0
    Views:
    322
    Earl Teigrob
    Aug 5, 2003
  2. JezB
    Replies:
    2
    Views:
    4,841
  3. David Lozzi

    Get newly created record's ID??

    David Lozzi, Dec 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    396
    Jacco Schalkwijk
    Dec 7, 2004
  4. =?Utf-8?B?bWN3b29x?=

    Error Debubbing newly created ASP.NET Project

    =?Utf-8?B?bWN3b29x?=, Nov 11, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,326
    Steven Cheng[MSFT]
    Nov 15, 2005
  5. Replies:
    1
    Views:
    545
    John Timney \( MVP \)
    May 31, 2006
Loading...

Share This Page