dom

Can I define an alias for a document object outside the function scope

This doesn't work in my browser - is this normal? It only works when I declare the alias for the document Object inside the function someFunc scope. var pic1 = document.getElementById('pic1'); var someFunc = function () { pic1.style.left = "100px"; } ...

Simple HTML Dom Parser, More Woes

Hello all, I am making use of the PHP Simple HTML DOM Parser to get the number 3869 from a HTML page. I tried this and a few other variations. foreach($html->find('span[class=searchresults_tab_number]') as $element) { echo $element->innertext . '<br />'; } But I keep getting nothing returned! All I need is the number from...

Is there a way to make an img tag not selectable in a browser?

I have an image in my page and I don't want it to pick up mouse clicks (as in the browsers inherent drag and drop or the drag select where it highlights the image in the browser.) Is there something I can do to the img or its parent dom element or the page to make the browser not do anything when I click on the image? I need to use the ...

Sometimes object.setAttribute(attrib,value) isn't equivalent to object.attrib=value in javascript?

It appears that sometimes object.setAttribute(attrib,value) isn't equivalent to object.attrib=value in javascript? I've got the following code, which works fine: var lastMonthBn = document.createElement('input'); lastMonthBn.value='<'; // This works fine lastMonthBn.type='button'; // This works fine But the following code doesn't...

jQuery parent selectors

Is there a jQuery parent selector that traverses up the DOM until the first match is found? Eg: <tr> <td> <div id="foo">hello!</div> </td> </tr> to find the row from the div I am using: $('#foo').parent().parent(); It feels like I should be able to write something like $('#foo').firstParent('tr'); but I can't find...

xpath/dom/term question

trying to get my head around a problem, not sure if there really is a solution, or a solution that's readily available. i'm trying to figure out if i can specify a "term" that's in the source of a webpage, and have the "blackbox" produce a fully qualified XPath for the DOM element that contains/has/uses the "term" in other words, if i h...

Fake loading/progress bar for slow non-Ajax page

Hi, I'm developing a site which serves some slow (up to around 4 sec. loading time) pages due to extensive database queries. In order to let the users know that the new page is loading (also to prevent multiple clicks), I'm displaying a div with a fake loading bar on the page where the users clicked a link to a slow loading page. Actu...

Why does this code alert three undefined values?

Why does this code alert three undefined values? <html> <head> <script type="text/javascript" language="javascript"> function doIt(form){ alert(form.elements.length) for (var i in form.elements){ alert(form.elements[i].value); } ...

Changing the source of an image (img) tag doesn't resize on IE

I have an img element in my DOM. Based upon user action, I compute a URL for an image, and change the image element's src attribute (using jQuery). The new image has a different size than the old image. This works fine on Safari, but IE does not resize the display for the new image's size. I do have a .load handler on the src change (in ...

How to distinguish between live and non-live NodeList collections?

Both document.getElementsByTagName('div') and document.querySelectorAll('div') return NodeList collection. The only difference is that first method returns live-collection and second one - a static one. The question is - is there any opportunity to distinguish one object from another only via inspecting these objects (i.e - not trying t...

Get div's size with mooTools

Hello ! I have some <div id="text">abc</div>. Is it possible to get it's size using JS/mooTools (width and height) when I did not set it with CSS ? ...

Why does someInputElement.type = 'button'; fail in IE?

I'm stuck trying to get the following javascript to work in IE: var lastMonthBn = document.createElement('input'); td.appendChild(lastMonthBn); lastMonthBn.value='<'; lastMonthBn.type = 'button'; // Fails in IE lastMonthBn.setAttribute('type','button'); // Also fails in IE For some reason, i cannot set the input to a button, it fails....

How do I Get Plain Text Beside an HTML Element using jQuery?

<span> <label for="305"> <input type="checkbox" name="305" style="vertical-align: middle;" value="305" id="305"> Farming General </label> </span> How do I get text "Farming General" using jQuery. Please do not ask me to change HTML structure ...

How does JavaScript know where an element is the DOM?

I was writing some code in jQuery, like: $(".middleContent").not(this).slideUp(); (this = currently active .middleContent element) And I was wondering how JavaScript knew the elements index in the DOM. I know each object is unique, but if you have a few elements with the same class how does it distinguish between them? It is to do ...

jQuery can't get a good formatted Id

Hi everybody, I have a problem with this fonction: function test(value){ var id = "'" + value + "'"; $(id).remove(); } It gets an "Id", add simple quotes and then call the remove function. The "value" is a generated id by php. For example, I can have: $var = "$the_id"; When the "test" function is triggered by a click, I get te fo...

Accessing a DOM object defined in an external SVG file

SVG standard allows to use and refer external SVG files. I have a file circle.svg that defines a circle object with id "the_circle". From the main SVG file I am able to include this circle and animate it, using SVG linking. I would also like to access the same circle object via javascript, how can I do this ? What is the javascript equ...

jQuery, best practice for passing around variables in the DOM?

I have a DOM element similar to Facebook's "View friends" popup. I have a table with a list of rows, on which I can add tags to those rows: <tr id="124"></tr> When the row is clicked there's a modal popup that is created and lets the user choose tags they want associated with that row, sort of like this: <div class="popup"> <div cl...

Implementing a simple floating navigation in Javascript

I am trying to implement a simple floating navigation using the DOM and Javascript. The following script is triggered using the onscroll event, but nothing happens and debugging through firebug has not been all that enlightening. function float_nav() { nav = document.getElementById("nav_container"); offset = window.pageYOffset + 'px...

Is it better to sprinkle PHP blocks in a document or use PHP DOM with anchors?

What's the best way to create an HTML document using PHP? I find that using <?php ?> blocks becomes quite messy when the page has a lot of dynamically generated content. I was thinking about using a PHP DOM manipulation library to insert the dynamic content into "anchors" into the document. This would result in a cleaner document layout ...

javascript to find the caller div. (or any other dom object)

I have the following html page: <div id="a" onclick ="javascript:click();">a</div> <div id="b" onclick ="javascript:click();">b</div> <div id="c" onclick ="javascript:click();">c</div> Now, The javascript function: function click() { // how do I know if it was 'a' , 'b' or 'c' to call me } Does anybody know how to find (in ev...