OunknownO
OunknownO

Reputation: 1206

my javascript say 'undefined' in variable when choosing element trough window.location.hash

I have an element with Id of

#accordion-tab-1

which I try to call with

$(`${window.location.hash}`).prop(`hash`)

and I get 'undefined' when I console.log it but when I do only

$(`${window.location.hash}`) 

I get element with that Id

Upvotes: 0

Views: 44

Answers (1)

Justinas
Justinas

Reputation: 43507

If your URL contains #accordion-tab-1 than all you need to do to select is use direct hash:

$(window.location.hash)

Also use normal quotes ' instead of . More: selecting element and than doing.prop('hash')leads toundefinedas DOM element does not have property namedhash`

Upvotes: 1

Related Questions