javascript

JQuery selectors not finding class on elements in table created by an Ajax XHR in Ruby on Rails

When using $('.foo').click(function(){ alert("I haz class alertz!"); return false; }); in application.js, and <a href = "" class = "foo" id = "foobar_1" >Teh Foobar </a> in any div that initializes with the page, when clicking "Teh Foobar" it alerts and doesn't follow the link. However, when using the same code in a...

What is the most stable modal dialog implementation across browsers to use from javascript for a web app?

I'm using a lot of JQuery in a web application that I am building for a client and I want to find an javascript implementation of a modal dialog that is reasonably stable across the following browser set. IE 7+ FF 2+ Chrome and Safari I've tried a couple of jQuery plugins but there always seems to be artifacts in one of these browsers....

help: reloading a page via ajax - when window.location=self.location doesn't work

so here on my homepage i got a <ul id="login"> <li> <a id="loginswitch" href="./login-page">log-in</a> | </li> <li> <a id="signupswitch" href="./signup-page">sign-up</a> </li> </ul> so via mootools, i get these anchor elements by id so that once they're clicked, a flashy div will popup below them that contains the login or signup ...

To detect if the user is closing the IE browser apart from onunload event, as it is triggerred when user does refresh etc.

hi, After being through numerous forums available on the net for last 5 days, I am still not able to completely track down the browser close event. My requirement is to generate a popup message, when user tries to close the browser. I have called my javascript function on body 'onbeforeunload' event. And I have hardcoded the conditions...

Is there a way to reference an existing CSS style from another CSS style using CSS or javascript?

If I have a style defined .style1 { width: 140px; } can I reference it from a second style? .style2 { ref: .style1; } Or is there a way via javascript/jQuery? --- Edit To clarify the problem, I am trying to apply whatever style is defined for a #x and #c to .x and .c without altering the CSS as the CSS is going to have update...

Instantiating a JavaScript object by calling prototype.constructor.apply

Let me start with a specific example of what I'm trying to do. I have an array of year, month, day, hour, minute, second and millisecond components in the form [ 2008, 10, 8, 00, 16, 34, 254 ]. I'd like to instantiate a Date object using the following standard constructor: new Date(year, month, date [, hour, minute, second, millisecond...

Screencapture from the browser using Javascript ??

I guess this is an odd one, and the answer is most likely it is not possible since it would represent a security breach; but I am looking for a way - if any - to get a screendump of content inside the browser. I don't need the entire window, but actually just need to dump the rendered state of an tag. It need to be cross platform and cr...

What would be quicker Flash or Javascript?

I have an idea for a website which involves a canvas area which has no limit to its size. Basically you would be able to add items to the canvas (notes, photos whatever really). You would then be able to drag the canvas which would move those items along with the canvas until they disappear of screen. If you dragged the canvas back the o...

How to JSON decode array elements in JavaScript?

I have a JavaScript array that, among others, contains a URL. If I try to simply put the URL in the page (the array is in a project involving the Yahoo! Maps API) it shows the URL as it should be. But if I try to do a redirect or simply do an 'alert' on the link array element I get: function(){return JSON.encode(this);} As far as...

Using Javascript With ASP.Net controls

Is there a best practice when it comes to setting client side "onclick" events when using ASP.Net controls? Simply adding the onclick attribute results in a Visual Studio warning that onclick is not a valid attribute of that control. Adding it during the Page_Load event through codebehind works, but is less clear than I'd like. Are th...

How do I trigger a BulletedList in LinkButton-mode with javascript?

Hi! I have a BulletedList in asp.net that is set to DisplayMode="LinkButton". I would like to trigger the first "bullet" from a javascript, can this be done? And if so, how? ...

jQuery Tips and Tricks

Miscellaneous Creating an HTML Element and keeping a reference, Checking if an element exists, Writing your own selectors by Andreas Grech The data function - bind data to elements by TenebrousX The noConflict function - Freeing up the $ variable by Oli Check the index of an element in a collection by redsquare The jQuery metadata plug...

Best way to break from nested loops in Javascript?

What's the best way to break from nested loops in Javascript? //Write the links to the page. for (var x = 0; x < Args.length; x++) { for (var Heading in Navigation.Headings) { for (var Item in Navigation.Headings[Heading]) { if (Args[x] == Navigation.Headings[Heading][Item].Name) { documen...

JavaScript Callback Scope

I'm having some trouble with plain old JavaScript (no frameworks) in referencing my object in a callback function. function foo(id) { this.dom = document.getElementById(id); this.bar = 5; var self = this; this.dom.addEventListener("click", self.onclick, false); } foo.prototype = { onclick : function() { this...

Cross-browser XPath implementation in JavaScript

I'm looking for a XPath library to query over XML documents in FF, IE, Opera and Safari... and couldn't find one. Have you seen any? ...

Can anyone recommend a good, free javascript for punycode to Unicode conversion?

I found this the other day: http://0xcc.net/jsescape/ but the punycode conversion doesn't work if there's a dash in the middle. For instance - I need to convert the punycode NIATO-OTABD to nñiñatoñ. Any help much appreciated ...

JavaScript style/optimization: String.indexOf() v. Regex.test()

I've recently come across this piece of JavaScript code: if (",>=,<=,<>,".indexOf("," + sCompOp + ",") != -1) I was intrigued, because to write this test I would have done: if (/(>=|<=|<>)/.test(sCompOp)) Is this just a stylistic difference, or does the author of the other code know something about optimization that I don't? Or per...

Access parent's parent from javascript object

Somthing like var life= { users : { guys : function(){ this.SOMTHING.mameAndDestroy(this.girls); }, girls : function(){ this.SOMTHING.kiss(this.boys); }, }, mameAndDestroy : function(group){ }, kiss : function(group){ } }; this.SOMTHING is what I imagine the format is, but it m...

Loading content as the user scrolls down.

I am building a blog type page, and I want to load items into the page as the user scrolls down, much like Google Reader, or Soup.io. How would you go about achieving this effect? I've seen some examples which read the height of the page, and have an onScroll even attached to the window so that as the user scrolls down we can test to see...

Preferred way to include relative reference to JavaScript in VS 2008 nested Masterpage.

Our base Masterpage has something like the following <head runat="server"> <title></title> <script type="text/javascript" src="<%= Page.ResolveClientURL("~/javascript/actions.js")%>"></script> <script type="text/javascript" src="<%= Page.ResolveClientURL("~/javascript/jquery/jquery-1.2.6.min.js")%>"></script> <asp:content...