Reputation: 85
Below is a code snippet of some frames I am trying to traverse using the DOM in javascript. I can use document.getElementById('raiseConfirm').click()
in FF and IE. It will not work in safari. I have tried a multitude of different things to try and get to the anchor with the ID raiseConfirm. It looks as if document.getElementById()
in this case doesn't find any of the elements in this frame. I have tried window.document
, self.document
, contentWindow
,contentDocument
, I have tried naming the frame like this, window.frames['gvdd'].document
, and when I test this, the document is an object and has things in it, but as soon as I try to use the function getElementById()
on it, it returns undefined
or null
.
Can anyone point me to the correct solution?
<form method="POST"
action="somescript.asp?CMD=POST&TODO=TRUE2"
id="FORMSV2DISPLAY"
name="FORMSV2DISPLAY">
<a id="raiseConfirm" href="#divConfirm" class="nyroModal">HERE IT IS</a>
<div id="divConfirm" style="display:none;">…</div>
Upvotes: 5
Views: 8459
Reputation: 19
document.getElementById() will not work in safari. Instead you need to use document.all... Therefore, JQuery comes into picture where it is supported by all browsers. This can be the major difference between Javascript and JQuery where to be used.
Upvotes: 1
Reputation: 85
I tried to say this before and it posted weirdly. I was able to fix this problem using JQuery and this is what I did.
$("#raiseConfirm").trigger("click");
Upvotes: 1
Reputation: 539
You could use jquery:
$('#raiseConfirm')
It will surely work on all browsers. That's the magic of jquery :)
And if you want to attach to the click event:
$(document).ready(function () {
$("#raiseConfirm").click(doSomenthing);
});
var doSomenthing = function () {
/* Something I do here */
}
Upvotes: 1
Reputation: 821
I tried this in JSFiddle. I couldn't get it to work in Safari without jQuery.
http://jsfiddle.net/belthasar/Zct4S/
Upvotes: 0