How to use 2 classes for the same function with jQuery

How do I run the same click function for 2 classes ? I have this : $(‘.buythis’).click(function(){ blabla } And I want to use the same line for a different class like : $(‘.anotherclass’).click(function(){ blabla } Now … how can I use the same click function without redeclaring it ? i want something like : […]

multiple variable assignment in javascript

Is there any way to multiple assignment in JavaScript like this: var a,b = “one” , “two”; when that equivalent with: var a = “one”; var b = “two”;

How to parsing Json Array in Javascript?

Json Array as following is easy to parse, { “movieCategories”: [ “a” : “Animation”, “b” :”Romance”, “c” :”Science Fiction” “d” : “Western” ] } Now,I have a Json response as following which is stored in movies.json file. { “movieCategories”: [ “Animation”, “Romance”, “Science Fiction”, “Western” ] } I am not sure how to parse the […]

How can I programmatically flip the value of an element attribute using JQuery?

I’m just starting to get into JQuery so I apologize in advance if this is a simple question. I’m working with the A List Apart article on Print Previews to try to get live Print Previews in the webapp that I’m working on. I’ve gotten it to work satisfactorily but I’m now trying to refactor […]

What is the best way to search for an item in a sorted list in javascript?

I have an ordered list of integers, and would like to search through them. What is the fastest way to do this? Is this the fastest it will work? Or can we optimise it because it is ordered? Array.prototype.Contains = function(value) { for (var index = 0; index < this.length; index++) { if (value == […]

How can I parse a JavaScript object with jQuery

What’s the foreach equivalent in jQuery (JavaScript) to parse through a JSON object and return key/value pairs?

Constantly loop a javascript array and display results to div?

I have a bunch of testimonials for my site which are currently on a page and am trying to get a div to display each 1 at an interval of 5 seconds, if the array reaches the last value it should start back to beginning of the array again. Here is what I have so […]

find and replace tokens in javascript

I have to do something like this string = ” this is a good example to show” search = array {this,good,show} find and replace them with a token like string = ” {1} is a {2} example to {3}” (order is intact) the string will undergo some processing and then string = ” {1} is […]

How do read/write <input> values in an HTML document with JavaScript?

I have an <input> in my document. There I want the user to do some input. var myVar = document.getElementById(‘userInput’).value; Then I want this value to be shown in another <input>. document.getElementById(‘Preview’).value = myVar; This code somehow doesn’t work. Can anybody help? Thanks in advance!

Where can I find a RegEx visualisation tool for JavaScript?

I’m debugging and commenting someone else’s JavaScript code at the moment but there’s some fiendish RegEx in it. While my knowledge of RegEx is fairly good, it would help to have a reliable visualiser to show each RegEx string as a railroad diagram or something similar. I found a plug-in for Eclipse, for use with […]