Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see if an element is a "br"

How can I see if an element is a "br"? I have tried to get it via .attr("type") and .type() but it always returns undefined! It would work on a input or button but not on a br element.

like image 626
mrmoor Avatar asked Dec 01 '22 21:12

mrmoor


2 Answers

Use the .tagName or .nodeName property. Then compare the value to "BR".

like image 174
timidboy Avatar answered Dec 04 '22 11:12

timidboy


How about just $(element).is('br')? For example:

<div class='tested' id='first'>
  <br class='tested' id='second' />
</div>

...
$('.tested').each(function() {
  var id = this.id;   
  if ($(this).is('br')) {
    console.log(id + ' is <br>');
  }
  else {
    console.log(id + ' is not <br>');
  }
});
// first is not <br>
// second is <br>​
like image 26
raina77ow Avatar answered Dec 04 '22 11:12

raina77ow