qzqaug
Last Updated: February 25, 2016
·
354
· rebyn
3

$ ( element exists ) { do something }

if ($("#nearby-Shop").length) {
    $("#go-By-some-bear").hide();
};

-Tu.

Say Thanks
Respond

1 Response
Add your response

1501
Feb007acc38e70d57f7b4c205f7e8b26

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 ·