javascript

jQuery: Is there a way to make this shorter and more elegant?

I have a code that looks like this: <div id="wrapper"> <img id="first" class="images" src="img/nike.jpg" /> <img id ="second" class = "images" src="img/golden.jpg" /> <img id = "third" class ="images" src ="img/a.jpg" /> <img id = "fourth" class="images" src="img/God__s_Canvas_by_Delacorr.jpg" /> </div> I wan...

How to fix erratic animation in jQuery

I have built a simple menu in jQuery http://vanquish.websitewelcome.com/~toberua/ Here is a sample of the menu <ul> <li id="your-residences"> <strong>Your Residences</strong> <ul> <li class="menu-1"><a href= "/~toberua/your-residences/deluxe-ocean-front-bure/">Deluxe Ocean Front Bure</a></li> <li cl...

How can I get the position of the cursor/caret within an HTML input element?

Should be pretty simple, but I can't seem to find it in Google. Your help is appreciated! ...

(Simple) Are HTML attributes allowed to have spaces between assignments

I'm doing some attribute parsing as a string, so I need to know how spaces are used in HTML/XHTML element attributes: <div id='myid' width='150px' /> Is this also correct? <div id = 'myid' width = '150px' /> If anyone knows other ways of iterating through attributes and their values using JavaScript, I'd be interested to know. ...

How to iterate through all attributes in an HTML element?

I need the JavaScript code to iterate through the filled attributes in an HTML element. This Element.attributes ref says I can access it via index, but does not specify whether it is well supported and can be used (cross-browser). Or any other ways? (without using any frameworks, like jQuery / Prototype) ...

Strip Html from Text in JavaScript except p tags?

I need to change RichEditor and TextEditor modes with JavaScript, now I need to convert Html to Text which is actually still in Html editor mode, so I need just p tags, but other Html can be stripped off. ...

How to emulate ScriptManager.RegisterStartupScript() in ASP.NET MVC project

I am using ASP.NET MVC project and jQuery to handle async requests. Sometimes for an async request I need an initialization JavaScript snippet to be returned and executed together with an HTML snippet (I want this JavaScript to be rendered on server). For now I am using my own ScriptsHelper class with a RegisterStartupScript() method (a...

How to get Visual Studio to remember javascript settings

Visual Studio 2008 is doing something that really frustrates me. I open a javascript file and start editing my code and it places the opening brace on the same line rather than on a new line. So I go to the text editor options and tick the boxes to put the braces on a new line and all is fine until the next day when I open a js file and ...

Dynamic Javascript File newline & carriage return

Hi All I am building a JS page dynamically with php using .htaccss to make .php into .js All works well apart from the output of the JS. IE $data = array('one', 'two'); foreach($data as $d){ echo "document.write('This is a test for array item ".$d."'); \r\n"; } Problem is it outputs it all on one line ie document.write('This ...

how to find coordinates of an HTML button or image, cross browser?

There was a thread on this in comp.lang.javascript recently where victory was announced but no code was posted: On an HTML page how do you find the lower left corner coordinates of an element (image or button, say) reliably across browsers and page styles? The method advocated in "Ajax in Action" (copy I have) doesn't seem to work in I...

Google Maps Trouble: Closures & Passing By Reference

Hi all, I'm having some Google Maps/Javascript problems. I think I know what the trouble is but just don't know a way round it. An example of my problem is here. Whatever marker you click on, the second shows up. I'm obviously passing the wrong info into my event listener but I just can't seem to get the code right. Here's a cut do...

cross-browser sidebar component

I want to create a cross-browser sidebar for a website. With the following features needs to be able to grab URL of main page - ok if only works for the current site hosted on the main website domain require no change to the main website pages themselves (but code could in added to a globally loaded .js file) work in major browsers (eg...

Handling combat effects in game development

I'm trying to nut out a highlevel tech spec for a game I'm tinkering with as a personal project. It's a turn based adventure game that's probably closest to Archon in terms of what I'm trying to do. What I'm having trouble with is conceptualising the best way to develop a combat system that I can implement simply at first, but that wil...

clearing an HTML file upload field via JS

i want to reset a file upload field when the user selects another option is this possible via JS? i'm suspecting that the file upload element is treated differently b/c it interacts with the user's FS, and maybe it's immutable basically, what i want is something like (pseudo) // choose selecting existing file $('#select-file').bind('f...

Convert a DOM Node or Document to XML in JavaScript

Say you in JavaScript are handed a single DOM element or Document (for example window.document), how would you turn that into valid XML? More specifically for my example, I have a web page that display's an SVG, this SVG has a lot of JavaScript to allow interaction. It's a graph display that let's you zoom in the graph and even make som...

Measuring Javascript performance in IE

Hi everyone, I have a webpage that heavily uses Javascript (AJAX requests, Google Maps API, HTML building, etc) and the page brings my PC to its knees whenever opened in Internet Explorer. I'm looking for some tools to help me find out which functions are taking the most time to finish. I have some basic profiling javascript functions, ...

Can anyone recommend me a JavaScript book?

Duplicate: good javascript books I'm a junior .Net developer. Many thanks. ...

What's a good tool for calculating web KSLOC?

For HTML, CSS, and JavaScript files, what's a good tool to run on source directories and get KSLOC? ...

Nokogiri: Sort Array of IDs according to order in HTML document.

I have an unsorted Array holding the following IDs: @un_array = ['bar', 'para-3', 'para-2', 'para-7'] Is there a smart way of using Nokogiri (or plain Javascript) to sort the array according to the order of the IDs in the example HTML document below? require 'rubygems' require 'nokogiri' value = Nokogiri::HTML.parse(<<-HTML_END) ...

How to get this element using jQuery selectors?

I use jQuery to get values of presaved elements from some websites, using paths like this: HTML BODY #bodyContainer #mainContentContainer #mainContent #productContentRight #swatchContent #colorSwatchContent SPAN The problem i faced when the websites page contains tables and there are same element in another similar path such as: ...