dom

Find non-active CSS properties

Is it possible to determine styles in a CSS file through Javascript? I am trying to detect CSS properties that will be applied to an element in a certain state, :hover in this case, but without those properties currently being active on the element. I had thought about cloning the element, appending the clone as a sibling with display:n...

Best way to transfer an array between PHP and Javascript

So I have an array of records retreived from a database. The array is in the format; $rows[0]['id']=1; $rows[0]['title']='Abc'; $rows[0]['time_left']=200; $rows[1]['id']=2; $rows[1]['title']='XYZ'; $rows[1]['time_left']=300; //And so on upto 10-20 rows What's the best/most elegant way of transferring this array over to my javascript...

If innerHTML is evil, then what's a better way change the text of a link?

I know innerHTML is supposedly evil, but I think it's the simplest way to change link text. For example: <a id="mylink" href="">click me</a> In JS you can change the text with: document.getElementById("mylink").innerHTML = new_text; And in Prototype/jQuery: $("mylink").innerHTML = new_text; works fine. Otherwise you have to rep...

How do I add a DOM element with jQuery?

I have a funciton that I am currently using to show a hidden div.a_type How can I modify this code so that instead of fading in the hidden div, I can add the new div to the DOM jQuery(function(){ // Add Answer jQuery(".add_answer").click(function(){ if(count >= "4"){ alert('Only 4 Answers Allowed'); }else{...

Load JSON at runtime rather than dynamically via AJAX

Hi, I don't think this can be done "cleanly", but I'll ask anyway. I have a system which needs to get a JSON resource via a REST GET call in order to initialize. At the moment the system waits until the onLoad event and fires an ajax request to retrieve the resource, which I don't think is the best way to do it, as the resource is need...

NS_ERROR_XPC_BAD_CONVERT_JS

I'm getting this error after trying to "appendChild" to an element that was just created (in for loop). What does this error mean? I suppose it's not possible to append sth. to an element that doesn't really exist in DOM. How do I fix it? "innerHTML" works, but I don't think it's really clean and proper way to do it. ...

Retrieving DOM textnode position

Hi, Is it possible to retrieve the geometric position (i.e. top/left offsets from either the parent element, the page, etc) of a text node? ...

How to handle programmatic change of the input element state in javascript

Hello, I've faced strange problem. While user change of check box input element on form produces adequate event programmatic change don't. How should I face this challenge? Code following: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; <html xmlns="http://www.w3.org/1999/...

Capturing mouse-clicks in the DOM with JQuery?

Background I'm using POST form submissions instead of links with concatenated arguments inside a Web application, so I can exercise control over input. Unfortunately this means users can't use the quick shortcuts they know to open links in new windows, like control-clicking or middle-clicking. Problem I've got what seems to be a work...

How do the various Javascript optimization projects affect DOM performance?

There's a lot of capital C, capital S computer science going into Javascript via the Tracemonkey, Squirrelfish, and V8 projects. Do any of these projects (or others) address the performance of DOM operations, or are they purely Javascript computation related? ...

Any JavaScript Frameworks with the aim of standard based cross-platform JS and DOM?

Hi, I'm trying to find any JavaScript frameworks whose sole aim is to standardize the DOM and JavaScript across all browsers. What I'm not looking for is frameworks which create their own API to solve these common problems. I want something that will allow me to call for example myElement.dispatchEvent("click") in Internet Explorer. Not...

Access DOM elements after ajax.load

I am inserting the HTML response from an AJAX call into my page, but then when I try to access those elements after they have been created, it fails.. This is how i retrieve and insert the HTML: $.ajax({url: 'output.aspx', data: 'id=5', type: 'get', datatype: 'html', success: function(outData) {$('#my_container').html(out...

Setting properties on anonymous DOM elements through JavaScript?

Let's say I'm generating markup through server-side code. I'm generating a bunch of HTML tags but I want to add custom attributes (properties). In JavaScript (if I had a reference to the DOM node I could write): var myDOMNode = ... myDOMNode.myCustomAttribute = "Hi!"; The issue here is that I don't want to qualify every element with ...

Can't get the object from a cell in jqGrid (jQuery)

This is the issue, when I define the ddl (drop down list or select box) I don't know the selected value. When a user edits a row, the user can select an item from the list. But the selected item isn't set. I want to set the selected item when the user clicks a button to edit the row. The proper way, I think, is to get the ddl that was ...

How to determine whether click happened on element's scrollbar or on its content

There is indeed method element.componentFromPoint(iCoordX, iCoordY) in Internet Explorer, but how do I differentiate a mouse click occurred in the content area of an element from the click occurred on its scrollbar in other browsers? ...

Possible to add large amount of DOM nodes without browser choking?

I have a webpage on my site that displays a table, reloads the XML source data every 10 seconds (with an XmlHttpRequest), and then updates the table to show the user any additions or removals of the data. To do this, the JavaScript function first clears out all elements from the table and then adds a new row for each unit of data. Recen...

Freezing the DOM to JavaScript: Overwriting DOM modification functions as no-ops

I'm writing a piece of code that requires the DOM of a website to remain frozen while arbitrary JavaScript runs. Attributes changing is fine but I can't have anything changing the original tag structure of the page! I know in JavaScript there are a base number of functions that can modify the DOM: appendChild( nodeToAppend ) cloneNode(...

How to hide new elements in jQuery?

I have this code: var $msg = jQuery('<div></div>') .hide() .appendTo(document.body) ; if ($msg.is(":hidden")) { console.log("hidden"); } else { console.log("visible"); } When run, it logs "hidden" on Firefox, but "visible" on Google Chrome. Is this a bug, or am I doing something wrong? ...

Browser agnostic C++ DOM interface

When programming in C++ against the browser's DOM each engine has a different set of interfaces, IE has the COM based MSHTML, Mozilla has the XPCOM based Gecko DOM etc. Is there a common API that has adapters for major browsers (and versions)? As a clarification, the application in question is a desktop application written in C++ wh...

How do I detect if jQuery is in a document navigated to in the WinForm WebBrowser control?

I have a Windows Forms application in C#/Visual Studio 2008 with an IE WebBrowser control. In the DocumentCompleted event, I want to search the WebBrowser.Document or WebBrowser.DomDocument to see if jQuery is already present in the page. What's a good way to accomplish this? Thanks! ...