How to check if an element exist , and if it does i want the insertAfter to be not valid.And if the element isn't exist, then i want the insertAfter to be valib but only once.My goal is to send only once insertAfter if an element isn't existing and if it does not send anything
Just do a length check. Assuming you have a selector #sel
, and you want to insert something after it.
var foo = 'something';
if ($('#sel').length) {
//do something if elem is present
} else {
$('#sel').insertAfter(foo);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With