문제

I am trying to change the class of a button in a parent window from a popup. I can change the display but the change in class does not seem to take effect. What is wrong with this code that run in the popup? The change to innerHTML and display works but not the className.

   var messages = window.opener.document.getElementById("messages");
   messages.innerHTML="Now linked to Facebook page at "+  link + ".";

   var firstmessage = window.opener.document.getElementById("firstmessage");
   firstmessage.style.display = 'block';
   firstmessage.style.className += ' notice_msg ';

   var choosefanpagebtn = window.opener.document.getElementById("choosefanpagebtn");
   choosefanpagebtn.style.className = "";
   choosefanpagebtn.style.className = "green_button";

Thank you.

도움이 되었습니까?

해결책

Remove the .style after choosefanpagebtn:

var choosefanpagebtn = window.opener.document.getElementById("choosefanpagebtn");
choosefanpagebtn.className = "green_button";

Should work. Not tested, let me know. Also, this line was unnecessary:

choosefanpagebtn.className = "";

Because you're not doing +=. If somehow you did that, and then

choosefanpagebtn.className += "green_button";

later, I could see that line being useful.

다른 팁

just use document.getElementById().className

var messages = window.opener.document.getElementById("messages");
messages.innerHTML="Now linked to Facebook page at "+  link + ".";
var firstmessage = window.opener.document.getElementById("firstmessage");
firstmessage.style.display = 'block';
firstmessage.className += ' notice_msg ';
var choosefanpagebtn = window.opener.document.getElementById("choosefanpagebtn");
choosefanpagebtn.className = "green_button";

Did you try removing the .style in .style.className ?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top