I am trying to call a function with parameters using jQuery’s .click, but I can’t get it to work. This is how I want it to work: $(‘.leadtoscore’).click(add_event(‘shot’)); which calls It works if I don’t use parameters, like this: But I need to be able to pass a parameter through to my add_event function. How can I do this specific
Select Element By CSS style (all with given style)
Is there a way to select all elements that have a given style using JavaScript? Eg, I want all absolutely positioned elements on a page. I would assume it is easier to find elements by style where the style is explicitly declared: the style is non-inherited (such as positioning) the style is not the default (as would be position:static). Am
How to silently hide “Image not found” icon when src source image is not found
Do you know how to hide the classic “Image not found” icon from a rendered HTML page when an image file is not found? Any working method using JavaScript/jQuery/CSS? Answer You can use the onerror event in JavaScript to act when an image fails to load: In jQuery (since you asked): Or for all images: You should use visibility: hidden
How can I share code between Node.js and the browser?
I am creating a small application with a JavaScript client (run in the browser) and a Node.js server, communicating using WebSocket. I would like to share code between the client and the server. I have only just started with Node.js and my knowledge of modern JavaScript is a little rusty, to say the least. So I am still getting my
Detect changes in the DOM
I want to execute a function when some div or input are added to the html. Is this possible? For example, a text input is added, then the function should be called. Answer 2015 update, new MutationObserver is supported by modern browsers: Chrome 18+, Firefox 14+, IE 11+, Safari 6+ If you need to support older ones, you may try
JavaScript – Get all but last item in array
This is my code: I want linkElementLink.href to grab everything but the last item in the array. Right now it is broken, and the item before it gets the second-to-last item. Answer Use pathname in preference to href to retrieve only the path part of the link. Otherwise you’ll get unexpected results if there is a ?query or #fragment suffix,
Accessing the content of other tabs in a browser
I am using Mozilla Firefox and I am trying to figure out a way to access the content of other tabs in the same window using JavaScript and the DOM (I am open to other techniques if exist). E.g., I want to run JavaScript code in tab1 which can find the title of some other tab. Basically I need this
why can’t i set window.onload in IE8?
I have the following function, which works fine in Firefox, but will do nothing in IE8 I want to open a webpage and immediately open the print dialogue. Answer If you have the hand on the page at url, place the call there. In the HTML, at the end of the BODY tag. Add a SCRIPT tag with your call
Restart an animated GIF from JavaScript without reloading the image
I am creating a slideshow of animations using animated GIFs. I’m crossfading from one animation to the next. The problem is: the only way I have discovered to ensure that the GIF starts animating from the first frame is to reload it each time it’s shown. The GIFs are 200KB or so each, which is way too much bandwidth for
Best way to document anonymous objects and functions with jsdoc
Edit: This is technically a 2 part question. I’ve chosen the best answer that covers the question in general and linked to the answer that handles the specific question. What is the best way to document anonymous objects and functions with jsdoc? Neither the PageRequest object or the callback exist in code. They will be provided to getPage() at runtime.