Skip to content

Tag: jquery

Set attribute without value

How do I set a data attribute without adding a value in jQuery? I want this: I tried: Everything else seems to add the second arguments as a string. Is it possible to just set an attribute without value? Answer The attr() function is also a setter function. You can just pass it an empty string. An empty strin…

How long is data in localStorage kept?

In JavaScript you have the object localStorage. How long this object will be active for? How long is the the data in it kept for? Answer The most correct answer to this question is: You don’t know. The user could wipe his/her local data at any time, and any type of local storage is subject to user prefe…

Set window.location with TypeScript

I am getting an error with the following TypeScript code: I am getting an underlined red error for the following: The message says: Does anyone know what this means? Answer window.location is of type Location while .attr(‘data-href’) returns a string, so you have to assign it to window.location.hr…