javascript

Is binding events in jQuery very expensive, or very inexpensive?

I just wrote a $().bind('event') function and then got concerned that this kind of a call might be very expensive if jQuery has to run through each element in the DOM to bind this event. Or maybe, it's just about as efficient as an event could be. The jQuery docs I've read aren't making this clear. Any opinions? ...

Using jQuery XPath selectors

I'm using a simple DOM parser function to catch XPath information of all nodes of a document For example, the HTML is: <div> <div>Everyday People</div> <div>My name is ACE</div> <div>Hello world</div> </div> Parsing the DOM to store the XPath info in the array arr: <script type="text/javascript" src="js/jquery/js/jquery-1.3.2....

need to access the checked checkbox

I need to get the value that has been assigned to the checkbox that is checked , and I've used for loop to show the checkboxes , now i need to access the values of the checkboxes that are checked only , Can anybody help me out with this ? foreach($inbox as $inbox_info) { <input type="checkbox" id="checkUnread" name="checkUnread" v...

Javascript validation:Block special characters

Hi Buddies, How can i restrict users fro entering special characters in the text box.I want only numbers and alphabets to be entered ( Typed / Pasted ) Any Samples ? Thanks in advance ...

regex does not remove non digits from string

I have the following string "item number:237728" I'm applying replace str.replace(/[^0-9]/g,''); but the string does not change, non digits are not removed. any idea why? thanks ...

need to get each checked checkboxes value which is in loop

<script> $(document).ready(function(){ function countChecked() { var n = $("input:checked").length; $("div").text(n + (n <= 1 ? " is" : " are") + " checked!"); } countChecked(); $(":checkbox").click(countChecked); }); </script> <style> div { color:red; } </style> </head> <body> <form> <inpu...

grid control with surrport for hierarchical data and frozen column ?

I am trying to find out a way of showing hierarchical data ( 3/4 levels nested data) in grid ( in IE6+ ). I want to show hierarchical data with vales for all columns at the parent and child nodes. Also I want to freeze first two columns in the grid. Be able to expand ( drill down ) the grid view by loading data on demand ( ajax) lookin...

JQuery add class on current item

I have this method that changes an larger image source on click. I need to add a 'current' class on the selected. I have no problem adding this class,but I need it to remove the class on the other, previous, selected item. This is the code I'm using at the moment: $(document).ready(function() { $("ul.timgs li a").click(function(e...

How can I programmatically invoke an onclick() event from a anchor tag while keeping the ‘this’ reference in the onclick function?

Is it possible to programmatically invoke a onClick-event for an anchor tag, while maintaining the 'this' reference to the anchor? The following doesn't work... (at least not in Firefox: document.getElementById('linkid').click() is not a function) <script type="text/javascript"> function doOnClick() { document.getElementByI...

how to select just the top element text?

i have this html: <span class="price"> $61.00   <span class="detailFreeShipping">With Free Shipping</span> </span> How to write a jquery selector which give me the price text only "$61.00"? i want to make it generic as i can because may be in some cases there is no inner span, just the parent one. ...

Javascript: constant properties

Hey, In javascript, can I declare properties of an object to be constant? Here is an example object: var XU = { Cc: Components.classes }; or function aXU() { this.Cc = Components.classes; } var XU = new aXU(); just putting "const" in front of it, doesn't work. I know, that i could declare a functi...

Call a url from javascript

Is there a way to call a url and get a response using javascript? I need the equivalent of ASP.NET: WebRequest req = HttpWebRequest.Create("http://someurl.com"); WebResponse webResponse = req.GetResponse(); I have an external url that holds some information I need and I want to call this url from javascript and parse the response in o...

Disable redirect on drag image or link

The problem is the following: I am using a tinymce editor (not related with the problem) and an external image manager aplication. We use the drag&drop functionality for users, to just drag the image from the image manager to the tinymce content area. However, there is a problem when the user inadvertantly drags the image outside the c...

Why is JavaScript considered bad by some?

Why is JavaScript allowed to be disabled in the browser? (i.e. Why is it considered bad?) ...

How to filter using Regx and javascript?

I have some text in an element in my page, and i want to scrap the price on that page without any text beside. I found the page contain price like that: <span class="discount">now $39.99</span> How to filter this and just get "$39.99" just using JavaScript and regular expressions. The question may be too easy or asked by another way...

prototype: Element.remove.bind(foo) doesn't work as expected

I have this snippet: self.puff({duration: 0, queue: 'end', afterFinish: Element.remove.bindAsEventListener(self) }); Self is an element; it is supposed to remove an element from document when all effects on it are completed. Unfortunately, this doesn't work, failing with "element.parentNode is undefined". If I replace Ele...

Possible to assign to multiple variables from an array?

Is it a standard way to assign to multiple variables from an array in JavaScript? In Firefox and Opera, you can do: var [key, value] = "key:value".split(":"); alert(key + "=" + value); // will alert "key = value"; But it doesn't work in IE8 or Google Chrome. Does anyone know a nice way to do this in other browsers without a tmp varia...

Object Oriented Javascript best practices ?

I'm finding myself coding a big project in Javascript. I remember the last one was quite an adventure because hacky JS can quickly becomes unreadable and I want this code to be clean. Well, I'm using objects to construct a lib, but there are several ways to define things in JS, implying important consequences in the scope, the memory ma...

Highlighting effect to text and/or image similar to be synchronized with audio

I am looking how to approach following problem: We have application that displays text with audio recorded material. We use Browser Control (Internet Explorer) in Delphi App to do this. We respond to events in Delphi code setting innerHTML for elements if we have to update the style ... Now, request is to add option to dynamically move...

JQuery - animate moving DOM element to new parent?

I have an image tag inside of a table cell, that I'd love to move to another table cell, and have that movement animated. The code looks something like this... <td id="cell1"><img src="arrow.png" alt="Arrow"/></td> <td id="cell2"></td> I'd like to move "arrow.png" to "cell2", and have some kind of transition effect, preferably with J...