javascript - How do I test if an element with a certain ID exists on a page in jQuery? -



javascript - How do I test if an element with a certain ID exists on a page in jQuery? -

in jquery, have written piece of code appears on every page of website.

var d = $('#someelement').offset().top;

however, not every page on website has element id of "someelement". unfortunately, on these pages lack such element, no jquery code works.

to solve problem, want test if element on page indeed has id of "someelement" , run code snippet above if there is.

how perform test? test solve problem? give thanks you.

$('#someelement').length homecoming 1 if element exists, 0otherwise.

javascript jquery

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -