$ ( element exists ) { do something }
if ($("#nearby-Shop").length) {
$("#go-By-some-bear").hide();
};
-Tu.
Written by Tu Hoang
Related protips
1 Response
FYI: https://coderwall.com/p/un7keg
COPYPASTA OF MY COMMENT:
It may be a good idea to assign the jQuery object to a var, especially if your selector works on a large DOM.
Concider:
var $testDivs = $("#test").find("div");
if ($testDivs.length) {
//use $testDivs without searching the DOM again
}
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Related Tags
#jquery
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#