GetElementById returns null or undefined in Safari

Below is a code snippet of some frames that I am trying to execute using the DOM in javascript. I can use document.getElementById('raiseConfirm').click() in FF and IE. He will not work on safari. I tried many different things to try to get to the anchor using the raiseConfirm id. It seems that document.getElementById() in this case does not find any of the elements in this frame. I tried window.document , self.document , contentWindow , contentDocument , I tried to name this frame like this, window.frames['gvdd'].document , and when I check this, the document is an object and has something in it , but as soon as I try to use the getElementById() function on it, it returns undefined or null .

Can someone point me to the right 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>​ 
+4
source share
4 answers

I tried to say it before, and it was weird. I was able to fix this problem using jQuery and that is what I did.

  $("#raiseConfirm").trigger("click"); 
+1
source

You can use jquery:

 $('#raiseConfirm') 

It will work in all browsers. This is the magic of jquery :)

And if you want to attach a click event:

 $(document).ready(function () { $("#raiseConfirm").click(doSomenthing); }); var doSomenthing = function () { /* Something I do here */ } 
+2
source

document.getElementById () will not work in safari. Instead, you need to use document.all ... Therefore, jQuery is included in the image, where it is supported by all browsers. This may be the main difference between javascript and jquery to be used.

+1
source

I tried this in JSFiddle. I could not get it to work in Safari without jQuery.

http://jsfiddle.net/belthasar/Zct4S/

0
source

Source: https://habr.com/ru/post/1414393/


All Articles