I have a set of DOM elements that I want to show only when a controlling checkbox is checked by the user. All of these items have a common class and are initially hidden:
.spec { display:none; }
In the click handler of the checkbox, I originally had the following,
which worked fine for existing elements. However, the tables are dyn...
I need to trigger an input change event, but only if the value changed. And I need this done from a keyboard event. Is there a way to invoke the browser's change mechanism which will either trigger the change event to fire, or will not depending on if the value was modified?
Example:
User clicks on an input field
User does not modify v...
Is this regular expression enough to catch all cross site scripting attempts when embedding HTML into the DOM. eg: Such as with document.write()
(javascript:|<\s*script.*?\s*>)
It is referenced in this document from modsecurity.com
http://www.modsecurity.org/documentation/Ajax%5FFingerprinting%5Fand%5FFiltering%5Fwith%5FModSecurity%5...
Hi
I am using this code snippet to add KeyDown event handler to any element in the html form
for(var i=0;i<ele.length;i++)
{
ele[i].onkeydown = function()
{
alert('onkeydown');
}
}
How can I know which key has been pressed on keydown event? I try this
for(var i=0;i<ele.length;i++)
{
ele[i].onkeydown = fun...
Hi, reading the documentation for java org.w3c.dom.ls it seems as a Element only can be serialized to a String with the java native string encoding, UTF-16. I need however to create a UTF-8 string, escaped or what not, I understand that it still will be a UTF-16 String. Anyone has an idea to get around this?
I need the string to pass in ...
I'm working on some ecmascript/javascript for an svg file and need to get the width and height of a text element so I can resize a rectangle that surrounds it. In html I would be able to use the offsetWidth and offsetHeight attributes on the element but it appears that those properties are unavailable.
Here's a fragment that I need to w...
var oFra = document.createDocumentFragment();
// oFra.[add elements];
document.createElement("div").id="myId";
oFra.getElementById("myId"); //not in FF
How can I get "myId" before attaching fragment to document?
...
What's the best way to insert an element into a page's HEAD directly before the closing tag using JavaScript?
...<HEAD>
<script>...</script>
<script>...</script>
<script>...</script>
<link .../>
<link .../>
<link title="MY NEW LINK ELEMENT" />
</HEAD>...
I know about the ol' insertBefore(sp1, sp2.nextSibling) trick, but that just let...
Long question
Is it possible to add a DOM element only if it does not already exists?
Example
I have implemented the requirement like so:
var ins = $("a[@id='iframeUrl']");
ins.siblings('#myIframe:first').remove().end().parent().prepend('<iframe id="myIframe" src="'+ins.attr("href")+'"></iframe>');
Is it possible to replace the se...
Using Prototype, I'm trying to extract a piece of text from the DOM - this would normal be a simple $().innerHTML job, but the HTML is nested slightly.
<td class="time-record">
<script type="text/javascript">
//<![CDATA[
document.write('XXX ago'.gsub('XXX', i18n_time_ago_in_words(1229311439000)));
//]]>
</script>
...
I got bit hard by this today:
function mk_input( name, val ) {
var inp = document.createElement( 'input' );
inp.name = name;
inp.value = val;
inp.type = 'hidden';
return inp;
}
As it turns out, setting the name of an element created via createElement doesn't work in IE. It doesn't cause an error or anything, it ju...
Hi, I'm pretty new to javascript, so bear with me if this is obvious.
Basically what I would like is to implement a little interface where when you type something in a textbox it gives an event. Sorta like how this stack overflow post preview works. I tried hooking into the OnChange event, but that only gives an event when they are done...
Hey..
I have a prototype representing a particual IFrame. That prototype have a function called GoToUrl(...) that opens the given url within the IFrame.
My question is: How do I create an "InternalDOM" property and make this property refer to the "window" object (the root DOM object) of the IFrame inside? In such way that: If my IFrame ...
I used to use cumulativeOffset() and getDimensions() to calculate the bounding box of elements, but just realized that cumulativeOffset returns the top left corner oft the start of an element. Meaning: if an inline element wraps, and the next line is more to the left than the start, I get a displaced bounding box.
After researching a bi...
This is a pretty academic question. I'm wondering how the browser is implemented as in what data structure or algorithm is used to map a CSS selector to a particular DOM element. Is it accomplished through a hash table? How does DOM child node knows that the style applied to parent also applies to itself etc. I've been looking at Moz...
I have a HTML like so:
<table>
<tr>
<th>colA heading</th>
<th>colb heading</th>
</tr>
<tr>
<td>colA content</td>
<td>colb content</td>
</tr>
<tr>
<th>colC heading</th>
<th>colD heading</th>
</tr>
<tr>
<td>colC content</td>
<td>colC content</td>
</tr>
</table>
That products the following output:
colA he...
I want to convert a Javascript DOM HTMLDcument to a string that I can write to a file. But how do you do the string conversion of the HTMLDocument to xml?!
Update If possible I'd like to see the html that is generated once any dynamic javascript rendering has been applied.
...
I created a hidden frame as follows:
var oHiddenFrame = null;
if(oHiddenFrame == null){
oHiddenFrame = document.createElement("iframe");
oHiddenFrame.name = "hiddenFrame";
oHiddenFrame.id = "hiddenFrame";
oHiddenFrame.style.height = "0px";
oHiddenFrame.style.width = "0px";
oHiddenFrame.style.position = "absolute";
oHiddenFrame.style.vis...
First,I created a hidden frame like this:
var oHiddenFrame = null;
if(oHiddenFrame == null){
oHiddenFrame = document.createElement("iframe");
oHiddenFrame.name = "hiddenFrame";
oHiddenFrame.id = "hiddenFrame";
oHiddenFrame.style.height = "0px";
oHiddenFrame.style.width = "0px";
oHiddenFrame.style.position = "absolute";
oHi...
Hi everyone !
Does anyone know how to set a new tagName to a tag using Jquery? Let's say i have an HTML document and I want to replace all 'fieldset' width 'div'.
Thanks in advance !
...