I am trying to capture a specific commented line. The following code works ok for every browser except IE of course:
<script>
var llf = jQuery('.select').contents().filter(function() {
return this.nodeType === 8 // Comment node
})[2].nodeValue.replace("LLF: ", "").trim();
console.log(llf);
alert(llf);
</script>
And this is the HTML:
<td class="select" nowrap="nowrap" rowspan="3">
<!-- NON IDEAL REASON: 1 hour time window -->
<b>$423.59</b><br />
<b>£267.50</b><br />
<!-- Policy Name: Investment Bank -->
<!--LLF: 1253.12 --> //This is the line I want to capture
If there is a way to do it for all browsers great but if you can think of a specific solution for IE + conditional comment is also fine.
Thanks!
IE doesn’t have
String#trim, which was only introduced recently in ES5, so it’s throwing an exception when you try to use it. But as you’re using jQuery, you can usejQuery.triminstead:Live copy | source – works for me in IE7 and IE9, so I’m presuming IE8 as well
I would recommend breaking that statement down a bit (not least so issues like this are easier to debug), and including the semicolon after the
=== 8.