Javascript - Is there a shorter way of writing... ?

Author Message
TKS

  • Total Posts : 188
  • Scores: 0
  • Reward points : 0
  • Joined: 5/16/2008
  • Status: offline
Javascript - Is there a shorter way of writing... ? Tuesday, July 22, 2008 4:17 AM (permalink)
0
window.event.srcElement.id=="idp" || window.event.srcElement.id=="idq" || window.event.srcElement.id=="idr" || window.event.srcElement.id=="ids"

Got any ideas?
 
#1
    mcnd

    • Total Posts : 50
    • Scores: 2
    • Reward points : 0
    • Joined: 4/27/2008
    • Status: offline
    RE: Javascript - Is there a shorter way of writing... ? Sunday, July 27, 2008 10:42 PM (permalink)
    0
    Try this

     ('/idp/idq/idr/ids/').indexOf('/'+window.event.srcElement.id+'/') > -1
     


    half the size, but i have not tried the speed


     
    #2
      TNO

      • Total Posts : 2094
      • Scores: 36
      • Reward points : 0
      • Joined: 12/18/2004
      • Location: Earth
      • Status: offline
      RE: Javascript - Is there a shorter way of writing... ? Saturday, August 02, 2008 4:25 AM (permalink)
      0
      window.event.srcElement.id === ("idp" ||"idq" || "idr" ||"ids")
      To iterate is human, to recurse divine. -- L. Peter Deutsch
       
      #3
        TNO

        • Total Posts : 2094
        • Scores: 36
        • Reward points : 0
        • Joined: 12/18/2004
        • Location: Earth
        • Status: offline
        RE: Javascript - Is there a shorter way of writing... ? Saturday, August 02, 2008 4:30 AM (permalink)
        0
        Here's another trick for you that may be useful:

        document.getElementById(("something" || "somethingElse")).tagName

        shortcut operators are nice
        To iterate is human, to recurse divine. -- L. Peter Deutsch
         
        #4
          TKS

          • Total Posts : 188
          • Scores: 0
          • Reward points : 0
          • Joined: 5/16/2008
          • Status: offline
          RE: Javascript - Is there a shorter way of writing... ? Thursday, August 21, 2008 5:17 AM (permalink)
          0
          Makes the code so much faster. Thanks guys! 
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9