dom

Javascript: Dynamically created html elements referencing an instantiated object

(For further background, this relates to the same piece of work as a previous question) I'm creating a JavaScript based webchat system using jQuery to make life much easier. All the webchat JavaScript code is in an external js file, which is then referenced and instantiated by the html page. <html xmlns="http://www.w3.org/1999/xhtml"&g...

Why does setTimeout(fn, 0) sometimes help?

I've recently run into a rather nasty bug, wherein the code was loading a <select> dynamically via JavaScript. This dynamically loaded <select> had a pre-selected value. In IE6, we already had code to fix the selected <option>, because sometimes the <select>'s selectedIndex value would be out of sync with the selected <option>'s index ...

Can I store custom attributes in HTML DOM like a database record?

When developing for browsers FF3 and IE6/7 with jQuery, are there any compatibility issues when setting custom attributes on HTML tags? First, I'm aware of jQuery's data() function and it essentially does what I want, but the data doesn't survive a clone() function. This is an issue when using the jQuery UI draggable/droppable plugins ...

In Javascript, can you extend the DOM?

In Javascript, you can extend existing classes by using its prototype object: String.prototype.getFirstLetter = function() { return this[0]; }; Is it possible to use this method to extend DOM elements? ...

How can I count text lines inside an DOM element? Can I?

I'm wondering if there's a way to count lines inside a div for example. Say we have a div like so: <div id="content">hello how are you?</div> Depending on many factors, the div can have one, or two, or even four lines of text. Is there any way for the script to know? In other words, are automatic breaks represented in DOM at all? ...

Fastest way to access a node

I have about thousand DIV tags structured this way: <div id="1"> <div class="1"></div> <div class="2"></div> ... </div> <div id="2"> <div class="1"></div> <div class="2"></div> ... </div> If I want to now access a particular node, say 'div#10 div.5' - what is the fastest way to do it using javascript DOM trave...

Cleaning javascript variable scope by removing it's code from DOM

Hi All Hope this jquery based simple code will help to explain the issue. html: <script> $('#remover').click(function(){ $('#block').empty(); }) $('#test').click(function(){ alert(remove1); // still displays the varibale }) </script> <div id="block"> <script> var remove1 = 'asasdsds'; var remove2 = 'asas...

In Javascript, can I get the exact coordinates on text cluttered with tags (childNodes everywhere?)

Hi, See the example below: it shows lines of text in a table (there's a good reason for this, but that's not the issue here). Basically, all I need is a function that alert()'s me the perfect coordinates of the text selection when I click on the link. By perfect coordinates, I mean: line number of the start of the selection, line numbe...

Using .onKeyUp and .onChange with Javascript DOM objects

I'm having a weird problem with some Javascript/DOM code I've ben playing with. I'm trying to assign the .onKeyUp and .onChange events/methods to a text input like so: form.elements["article"].onkeyup = "alert('test');"; Oddly, assigning using that method is doing nothing, and I'm forced to do this manually using: form.elements["arti...

Ways to increase performance when set big value to innerHTML

I'm trying to set a huge (200K) response to innerhtml of a node. The goal is to get better time than 2.7 sec in internet explorer 6. Any ideas?, Thanks ...

Deselect contents of a textbox with javascript

I understand that with javascript you can select the contents of a textbox with the following code (in jQuery): $("#txt1").select(); Is there a way to do the opposite? To deselect the content of a textbox? I have the focus event of a series of textboxes set to select the contents within them. There are times now that I want to focu...

How to increase the page height by X pixels by using only javascript

Assume an HTML page: <html> <body> .. html content (outside of our control) .. .. javascript block .. .. some more html content (outside of our control) .. </body> </html> Assume further that the only part of the HTML page that we're able to control is a javascript block in the middle of the page. Using that javasc...

Can I append an Ajax requestXML object to my document tree all in one go?

Greetings. Here is an XML object returned by my server in the responseXML object: <tableRoot> <table> <caption>howdy!</caption> <tr> <td>hello</td> <td>world</td> </tr> <tr> <td>another</td> <td>line</td> </tr> </table> Now I attach this fragment to my document ...

Building HTML (~= DOM) using jQuery

I may be doing something wrong, but I haven't been able to find a good way to build basic HTML/DOM structures, like lists, dynamically. Simple example would be building a table (table element, row, cells, with properly escaped text content) given input like json (objects). The problem I have is that most calls (like ".append()", ".html(...

Strict doctype preventing access to DOM variable in FireFox

I don't know if this is a well known 'thing' or something new in whatever version of Firefox it just updated itself too - but in either case I have no idea how to google for this question so I'll have to ask it here. I have a DIV in my DOM that I am trying to directly access by id, in the most simplest form like this: alert(btnTest.id...

IE not letting me set a textarea value with javascript.

I'm trying to change the value on a <textarea> element. This code works great in Firefox, but IE claims there's an error onblur and doesn't set the value. <textarea name="comment" id="comment" rows="8" cols="80" style="color:grey;" onfocus="if(this.value=='Add a comment...') {this.style.color='black'; this.v...

How can you set focus to an HTML input element without having all of the HTML?

First, the background: I'm working in Tapestry 4, so the HTML for any given page is stitched together from various bits and pieces of HTML scattered throughout the application. For the component I'm working on I don't have the <body> tag so I can't give it an onload attribute. The component has an input element that needs focus when the...

how do I programmatically click on an element in firefox?

In IE, I can just call element.click() from javascript - how do I accomplish the same task in Firefox? Ideally I'd like to have some javascript that would work equally well cross-browser, but if necessary I'll have different per-browser javascript for this. ...

DIV auto scroll

I have a div that has a large number of items in it. I select these items dynamically by clicking a button, overflow is auto in my case. What I want is that when an item that is not visible is selected to scroll the div so that can be visible. How can I do this? ...

Translate the following jQuery code to YUI 2.x code

Disclaimer: I have no experience using YUI at all. I was wondering how the following lines of jQuery code would look when written in YUI. Also, since YUI is using a hierarchical dependency system, which .js files need to be included in order for the code to work? 1. Given the ID of an HTML element, apply multiple style rules on the e...