MiGU
MiGU

Reputation: 380

jquery find function returning html nonexistent comments

I have the next html lines:

<div class="large-6 small-12 columns">

   <div class="left">
      <label>Supplément</ label>
   </div>

   <p class="left itemSupp">0 €</ p>

</div>

I'm using jquery get function to get that '0 €' text. In order to do so, I have the next js code:

$(document).find('.itemSupp').html();

But that's not exactly what I get. In fact, when I use js console:

console.log($(document).find('.itemSupp').html());

It's shows:

0 €<!-- p-->

It's a bit weird because I can't find that comment line in the whole file. I've both tested Chrome and Firefox consoles and I get the same result.

I'm using Foundation framework, in case that helps.

Upvotes: 0

Views: 69

Answers (2)

user3507600
user3507600

Reputation: 1075

Not sure exactly why, but it appears to be because your close tag is </ p> instead of </p>.

Demo

Add the space back in and re run the demo, you should see what you have reported. Without the space it should just print 0 €.

Edit:

According to w3 HTML syntax information, any whitespace in a closing tag is expected after the tag (the / and the tag must be adjacent).

Edit 2:

As user3388636 put in his answer, you may want to consider using the text() function instead of html(); unless of course there is a reason you need the HTML versus just the text.

Upvotes: 4

Nick
Nick

Reputation: 1570

Remove space </p>.

Use this:

$('.itemSupp').text();

Upvotes: 2

Related Questions