Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
93
rated 0 times [  96] [ 3]  / answers: 1 / hits: 121903  / 12 Years ago, wed, november 28, 2012, 12:00:00

Is this code good?



var wlocation = $(this).closest('.myclass').find('li a').attr('href');
if (wlocation.prop !== undefined) { window.location = wlocation; }


or should I do



var wlocation = $(this).closest('.myclass').find('li a').attr('href');
if (wlocation.prop !== undefined) { window.location = wlocation; }

More From » jquery

 Answers
5

I like this:



if (wlocation !== undefined)


But if you prefer the second way wouldn't be as you posted. It would be:



if (typeof wlocation  !== undefined)

[#81747] Tuesday, November 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alfonsok

Total Points: 386
Total Questions: 101
Total Answers: 90

Location: Puerto Rico
Member since Sun, Jun 27, 2021
3 Years ago
;