Wednesday, September 25, 2013

Javascript: Commented out HTML markup and DOM traversal

Here's the use case and different behaviors I observed in IE, Chrome and Firefox browsers today.

I have the markup snippet below in my jspf.

<table>
    <tr>
      <td>
          <input type="checkbox" id="someId" class="inputClass">
      </td>
      <td>
          <!-- <label  for="someId" >Your Label Here</label>  -->
          <label  for="someId" class="labelClass">Your Label Here</label>
      </td>
    </tr>
</table>

I wanted to get the first element node found inside the second <td>. 
When traversing this particular snippet using the nextElement method, IE is returning the commented out <label> tag as the first element node. Chrome and Firefox is smart enough to return the uncommented <label> tag.

I thought of trying jsp comment tags in place of the html comment tags to see if I would get a different result. I just didn't have enough time.

No comments:

Post a Comment