Is there a way in javascript to make it so that an “onclick” works for all members of a particular class? So if I have objects A and B that are both of type X, clicking on either of them will call the same function? But that function should only work on whichever of A or B was called, not
Tag: javascript
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…
Dynamic textbox creation with db using ajax/javascript/php
I have two tables. company_details and company_specials. Each company_details can have multiple specials. I display the company details at http://eurothermwindows.com/ed/admin.php The first row and fourth row that has the 0 in the active column is from company_details and the rows below are from company_speci…
How to remove elements that were fetched using querySelectorAll?
This seems like something that would have a quick answer, but I can’t find one. Maybe I’m searching the wrong terms? No libraries please, though I don’t need cross-browser fallbacks, I’m targeting all the latest versions on this project. I’m getting some elements: This is working…
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…
localStorage – use getItem/setItem functions or access object directly?
Are there some benefits of using the methods defined on the localStorage object versus accessing the object properties directly? For example, instead of: I have been doing this: Is there anything wrong with this? Answer Not really, they are, basically, exactly the same. One uses encapsulation (getter/setter) …
Isolate part of a string from index to next whitespace?
What’s the best way to do this solve for this next whitespace? result: things Answer You could do the whole thing with a regular expression: What that does is match an exclamation point, followed by some amount of non-whitespace (that’s what S means — s with a lower-case “s” matches wh…
How can I add action to just created object in JavaScript?
I have some strange problem with action adding to dynamically created objects. The thing is, when I am adding it, together with assigning action, the action is done automatically, not by pressing mouse button. Now, after some changes based on previous functions what I’ve achieved is totally not working …
In Chrome, resource isn’t loaded when $(document).ready() is triggered. Why?
In Firefox and IE, the SVG <embed> (SVG) document is retrieved when $(document ).ready() is called. In Chrome, the getSVGDocument returns null instead when $(document ).ready() is called. (Although it seems to find it approx 7ms after, as shown by the setTimeout.) Why does Chrome not find the loaded <…