Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. unexpected identifier: quick question

unexpected identifier: quick question

Scheduled Pinned Locked Moved JavaScript
questionjavascripthelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shoysmTP
    wrote on last edited by
    #1
        var tempDiv = "
    

    ";
    divs.push(tempDiv);

    is this code valid in javascript? i'm getting error in chrome console that says unexpected identifier the error is on first line.

    Richard DeemingR 1 Reply Last reply
    0
    • S shoysmTP
          var tempDiv = "
      

      ";
      divs.push(tempDiv);

      is this code valid in javascript? i'm getting error in chrome console that says unexpected identifier the error is on first line.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      If that's the precise code you've got, and it hasn't been mangled by the site, then it's not valid Javascript. Nested quotes need to be escaped:

      var tempDiv = "<div class=\"someClass\"></div>";

      // Or:
      var tempDiv = '<div class="someClass"></div>';

      You also need to remove the spaces around the = character for the string to be valid HTML.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        If that's the precise code you've got, and it hasn't been mangled by the site, then it's not valid Javascript. Nested quotes need to be escaped:

        var tempDiv = "<div class=\"someClass\"></div>";

        // Or:
        var tempDiv = '<div class="someClass"></div>';

        You also need to remove the spaces around the = character for the string to be valid HTML.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        S Offline
        S Offline
        shoysmTP
        wrote on last edited by
        #3

        thanks a lot... that was helpful

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups