I was playing with jsfiddle here: http://jsfiddle.net/dm9eebz9/
HTML
<div id="wrapper">
<p class="body">Line 1
<br>
<br>Line 3</p>
<p class="body">Line 1
<br>Line 2
<br>
<br>
<br>
<br>Line 6</p>
<p class="body">Line 1
<br>Line 2</p>
</div>
Javascript/jQuery
$('#wrapper p.body').each(function () {
var temp = $(this).innerHTML;
this.innerHTML = temp.replace(/(<br>)+/gim, "<br>");
});
My goal was to try to get rid of more than 2 <br>'s when they occur. However, it doesn't seem to recognize temp. Is this jsfiddle behavior, or am I making an obvious error?
innerHTMLproperty on a jQuery array.brif there are more than 2 consecutivebrnodes? I.e. it would remove the last twobrin the second paragraph?$(this)[0]and it gives you back that raw javascript.$(this)[0]returns a DOM element which lets you access the DOM API. Of course you are using JavaSCript, but jQuery is JavaScript as well.