dom

Internet Explorer lastChild.id not working correctly.

For chrome, firefox, and safari the following code seems to work and be able to retrieve the id of the last tr in a table. var table = document.getElementById( tableId ); var rowid = table.lastChild.lastChild.id; The goal is to use each rows id to keep track of what row number it is. I am using javascript to dynamcially add and re...

Why is the jQuery html() method ignoring line breaks?

I'm building a page of thumbnails with jQuery like this: ID=this.id; $('#thumbs').empty().html('<span class="title">'+$('#'+ID).html())+'</span><br />'; var i = 1; for (i=1;i<=count[ID];i++) { $('#thumbs').append('<img class="thumb" src="graphics/thumbs/'+ID+'/'+i+'.jpg" />'); } The idea being that the <span> would appea...

jQuery Error: Invalid object initializer

Hi, I have the following code in my page: <div id="data_body_container" style="overflow: auto; width: 880px; height: 500px;"> ... </div> and then below in the site: <script type="text/javascript"> $(window).resize(function() { var windowWidth = $(window).width() - 50; var windowHeight...

Extending native elements in JavaScript via prototype?

Would you consider extending the native elements via the prototype dangerous? I see some frameworks such as Prototype doing this so I have started to wonder if I dare to do that too. I am worried about implementing things like addClassName and make it collide in the future in a way that I can't resolve any other way than rewriting the ...

characters not allowed in DOM ids by spec, and by browser

The following question is a good rundown on what the spec says about the contents of the id attribute: http://stackoverflow.com/questions/1077084/what-characters-are-allowed-in-dom-ids my question is, how well do browsers adhere to this spec? I am pretty sure that i can use all numeric ids in firefox for example. ...

Using Jquery to parse html of a webpage, modify it, then reinsert it into webpage

Hi. I currently am trying to add tags around certain words in a webpage. This webpage can have many different id's, classes, and names, so it's important that if I'm trying to put a span around "foo" I do the following: <p class='foo'>blah blah blah foo blah blah blah </p> changes into <p class='foo'>blah blah blah <span class='ba...

Syncing column width of between tables in two different frames, etc...

For reasons which are somewhat unavoidable (lots of legacy code, compatibility, design needs) I have the following problem: I have two tables, one directly below the other, but split between two frames (see the pseudo-example below my sig.). I need the column widths of these tables to synchronize exactly so that these two tables 'act...

Dynamic DOM and jQuery

I open an ajax modal window with jQuery. How can I update the DOM and make the new elements available for jQuery to use? ...

How to move the cursor into a input text box by clicking a label tag?

Hi All, How to move the cursor position into a input text box by clicking a label tag? Much appreciated ...

How to declare an XML namespace prefix with DOM/PHP?

I'm trying to produce the following XML by means of DOM/PHP5: <?xml version="1.0"?> <root xmlns:p="myNS"> <p:x>test</p:x> </root> This is what I'm doing: $xml = new DOMDocument('1.0'); $root = $xml->createElementNS('myNS', 'root'); $xml->appendChild($root); $x = $xml->createElementNS('myNS', 'x', 'test'); $root->appendChild($x); ec...

why $(window['iframeName'].document.body).html() doesn't work when i change .attr('src')

Why doesn't $(window['iframeName'].document.body).html() ...work when i change .attr('src') When i set the src attribute of iframe to any url when i creating the page, this code $(window['iframeName'].document.body).html() ...will work. But when i change the src attribute by .attr('src',"www.google.com.sa") and wait to load the...

Should I always store a string of HTML instead of printing out portions of it at time?

I've come across dozens of scripts in which html is echo'd out instead of being stored. I'm wondering if it's generally a good practice of always storing the html in a string due to the flexible nature? A random example would be that I have a function that returns the html for a dynamic subnavigation. I'm printing the opening div tag, p...

Help me implementing addClassName in my JavaScript project the right way

Hi, I find myself often needing addClassName and removeClassName functions for Elements. However, I dare not to extend the native Element due to potential collisions. So, now I am wondering what to do. I took a look at ExtJS, and it achieves this like: var element = document.getElementById('...'); var elem = new Ext.Element(element); ...

jQuery: Can content loaded via ajax update the DOM?

I have a list of posts that is loaded onto my page using ajax like so: var fm = <?php echo $from_user ;?>; $("#microblogposts").load("posts.php", {from_user: fm}, function(){ }); Within this list of posts I have a function to delete posts from the list: //START POST DELETE FUNCTION $("form#deletepost").submit(function() { /...

Freeze Dom Manipulation

Is there a way to make firebug (or any other browser, or using any other tool) stop any dom manipulation from happening? Sometimes layout debugging a screen filled with on hover events is impossible, as the elements may disappear, and you can't see their compound layout. ...

Getting a reference to the parent IFRAME

Say I have a reference to a document object, which is contained inside an IFRAME. How do I get a reference to the container IFRAME? .parentNode and .ownerDocument both return null. Please note that no context information is available (e.g. solutions like 'window.xxx' will not work) - all that's available is a reference to the document ...

Is a <head> element always available in the DOM, even if absent in the HTML markup?

Every browser I've observed creates a <head> element that's accessible in the DOM even if there are no explicit <head></head> tags in the document's markup. However, Google Analytics uses the following code for dynamic script insertion: (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async...

xpath with dom document

I'm trying the find a xml node with xpath query. but i cannot make it working. In firefox result is always "undefined" and chrome throws a error code. <script type="text/javascript"> var xmlString = '<form><name>test</name></form>'; var doc = new DOMParser().parseFromString(xmlString,'text/xml'); var result = doc.evaluate('/form/name'...

How to call a JavaScript callback from a Java applet thread?

I have some long-running Java code running in a thread started by a Java applet. As soon as the code has finished, it has information for the user. I'd like to pass this information to a JavaScript callback in a thread-safe way. Just using the Java DOM API to modify the HTML document is not good enough, unless my JavaScript callback gets...

Insert HTML after a selection

I want to be able to double-click to select some text in a div, which then triggers a JavaScript function that inserts some HTML after the selected text, much like the 'edit/reply' feature in Google Wave. I have already established how to trigger a function on double-clicking, it is locating the selection and subsequently inserting HTML...