Handle &

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Handle &

    Here is my code ...

    [code=HTML]
    <td onclick="alert( this.innerHTML) ;">Debasis &amp; Jana</td>
    [/code]

    When it alerts then it prints Debasis &amp; Jana, if my innerHTML is Debasis & Jana then it still prints the same.
    Please Help!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use textContent for standards-compliance (Firefox/Opera) and innerText for IE.

    An alternative is to use firstChild.data or firstChild.node Value.

    Comment

    • vee10
      New Member
      • Oct 2006
      • 141

      #3
      Thanks for the solution

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        No problem. Were you looking for the same solution or are you dmjpro in disguise? :p

        Comment

        • vee10
          New Member
          • Oct 2006
          • 141

          #5
          Hi
          In my project i faced the same situation not only for & then i don't know this soln so i have written my own code for displaying & so by seeing this soln now i understood that i have to dig more in to the concepts


          Originally posted by acoder
          No problem. Were you looking for the same solution or are you dmjpro in disguise? :p

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by acoder
            Use textContent for standards-compliance (Firefox/Opera) and innerText for IE.

            An alternative is to use firstChild.data or firstChild.node Value.
            Thanks Acoder :-)
            Actually i got a problem that's why i could not come :-(
            Now, what i tried that ....
            [CODE=JAVASCRIPT]this.innerHTML. replace('&amp;' ,'&')[/CODE]
            Still it prints the same. Is not the property innerHTML is String?
            The same thing tried with a string...expect ed result coming :-)
            Code:
            alert('&amp;'.replace('&amp;','&')) //it prints &
            Why? Could you explain Acoder?

            lol ............. :-)
            Actually I wrote Apersandamp; but it comes as & only ..you know what i mean?
            Last edited by dmjpro; Aug 18 '08, 02:30 PM. Reason: found out some points after submitting......

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              innerHTML will display HTML, not just text. In your <td>, put a <span> element and see the output.

              Comment

              Working...