Welcome to WebmasterWorld Guest from

Forum Moderators: open

jQuery, run only if element exists

.on('load',...) or .length

1:04 am on Jun 30, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Mar 15, 2013
posts: 826
votes: 71

I only want a function to run if an element exists on the page... which would you guys do, and why?

if ($(element).length) {
// do this

.on('load', function() {
// do this