Skip to content
Advertisement

Tag: html

Firing DOM mouse events programmatically from JavaScript

Is it possible to programmatically fire mouse events in DOM? My sample case would be the following: Whenever the user clicks the div over an iframe, I would like to somehow propagate the event to the iframe, too. (Here we assume that the iframe src is in the same domain.) Answer Whilst you can inject events into browsers’ event-handling systems

Getting HTML form values

How can I get the value of an HTML form to pass to JavaScript? Is this correct? My script takes two arguments one from textbox, one from the dropdown box. Answer HTML: JS:

How do you use window.postMessage across domains?

It seems like the point of window.postMessage is to allow safe communication between windows/frames hosted on different domains, but it doesn’t actually seem to allow that in Chrome. Here’s the scenario: Embed an <iframe> (with a src on domain B*) in a page on domain A The <iframe> ends up being mostly a <script> tag, at the end of which’s

How to scale an imageData in HTML canvas?

I have a canvas in my webpage; I create a new Image data in this canvas then I modify some pixel through myImgData.data[] array. Now I would like to scale this image and make it bigger. I tried by scaling the context but the image remains small. Is it possible to do this? Thanks Answer You could draw the imageData

jQuery: how to change tag name?

jQuery: how to change tag name? For example: I need Yes, I can Create DOM element <div> Copy tr content to div Remove tr from dom But can I make it directly? PS: results in DOMException. Answer You can replace any HTML markup by using jQuery’s .replaceWith() method. example: http://jsfiddle.net/JHmaV/ Ref.: .replaceWith If you want to keep the existing markup,

Adding HTML elements with JavaScript

So, if I have HTML like this: How can I use JavaScript to add an HTML element where that blank line is? Answer As you didn’t mention any use of javascript libraries (like jquery, dojo), here’s something Pure javascript. or

I am trying to make a simple toggle button in javascript

I am trying to make a simple toggle button in javascript. However, the button will only turn “OFF” and will not turn back “ON” I am running:HP Netbook : Ubuntu Linux 10.04 : Firefox for Ubuntu 1.0. Answer Both of your if statements are getting executed one after each other, as you change the value and then immediately read it

How to get caller element using JavaScript?

I have a table with id “tbl” and it has 2 rows and 3 cols. Each cell (td) has an explicitly defined id. Also, the table has an onclick event that calls a function foo(). The onclick() would be generated whenever any cell is clicked. The table tag is: I also tried javascript:foo(this) I want to find out the id

Advertisement