SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simply javascript and element's class attributes functions...

    I noticed that when in the book the author write functions (in the Core book library) that for example add classes to the html element "class" attribute or remove them etc in the function code it doesn't check first if the class attribute is present on that element. If it isn't present i think the element node reference property (in the javascript code) that try to access that class html attribute will return "null" and the code doesn't control this event.

  2. #2
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another thing. In the book it is said that it is more appropriate and secure to declare/assign variables always with the "var" keyword expecially inside function so we can mantain the local scope in which the variable was declared. Then on the chapter that talks about events on page 125 for example, the author assign a value to a variable called "event" but without the "var" keyword. Is the author creating a global variable here inside this function?

  3. #3
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no one?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    You are one of the very few people with that book, so we can't see the code you're talking about.

    Please post sample code about what you're questioning, and answers can be provided.

    About the event variable, if it is passed as a function argument, it shouldn't be redefined in the function itself. Do you have a code sample to post so we can clarify this?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •