How to capture commented HTML using JavaScript?

I would like to know if a comment can be written using JavaScript.

The remark will look as follows:

<div id='ContainerId'>
<!-- NON IDEAL REASON: 90 min time window depart arrive -->
<b>1,107.45 GBP</b><br />
<!--LLF: 1107.45 -->
</div>

I need to store this value (in this case 1107.45) inside a variable.

This does not work:

var LLF = jQuery("contains('LLF')");

Any ideas?

Thank!

+3
source share
1 answer
$('#ContainerId').contents().filter(function(){
    return this.nodeType === 8 // Comment node
});

Live demo

And the full code:

var comment = $('#ContainerId').contents().filter(function() {
    return this.nodeType === 8 // Comment node
})[0].nodeValue;

console.log(comment.match(/\d+\.\d+/g));​​​​​

Live demo

+5
source

All Articles