Windows 10 reached EOS (end of support) on October 14, 2025. If you are on Windows 10, see this article.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

What about attribute 'checked' of input? What i should do: "removeAttribute('checked')" or "checked = false"?

  • 5 பதிலளிப்புகள்
  • 2 இந்த பிரச்னைகள் உள்ளது
  • 24 views
  • Last reply by cor-el
  • தீர்வுற்றது

SCRIPT function vibor(){ if (document.getElementById('autologin').checked = true){ document.getElementById('autologin').removeAttribute('checked'); document.getElementById('autologin1').style.backgroundPosition = 'left top'; } else { document.getElementById('autologin').createAttribute('checked'); document.getElementById('autologin1').style.backgroundPosition = 'left bottom'; } } /SCRIPT If i used "removeAttribute", in face input is checked. But if i used "checked = false", input's face not checked, but it checked in HTML code (if FireBug don't lies). Please, helped me somebody! I don't know what i should do.

P.s. Please, don't scold me for my English. I don't speak English very much and that have a cause - i'm 14 years old and lived in Russia, where nobody may helped me.

SCRIPT function vibor(){ if (document.getElementById('autologin').checked = true){ document.getElementById('autologin').removeAttribute('checked'); document.getElementById('autologin1').style.backgroundPosition = 'left top'; } else { document.getElementById('autologin').createAttribute('checked'); document.getElementById('autologin1').style.backgroundPosition = 'left bottom'; } } /SCRIPT If i used "removeAttribute", in face input is checked. But if i used "checked = false", input's face not checked, but it checked in HTML code (if FireBug don't lies). Please, helped me somebody! I don't know what i should do. P.s. Please, don't scold me for my English. I don't speak English very much and that have a cause - i'm 14 years old and lived in Russia, where nobody may helped me.

தீர்வு தேர்ந்தெடுக்கப்பட்டது

It is not an attribute, but a Boolean JavaScript variable and you can't remove it.

Note that if (document.getElementById('autologin').checked = true){} will set that variable always to true.

You probably want this:

function vibor(){
 if (document.getElementById('autologin').checked == true){
   document.getElementById('autologin').checked = false;
   document.getElementById('autologin1').style.backgroundPosition = 'left top'; 
 } else {
   document.getElementById('autologin').checked = true;
   document.getElementById('autologin1').style.backgroundPosition = 'left bottom';
   }
} 
Read this answer in context 👍 1

All Replies (5)

Если есть кто-то русскоговорящий, то объясняю: при использовании removeAttribute удаляется сам атрибут checked, но галочка на виду остаётся. А при юзании checked = false галочка убирается только на виду, но остаётся в html'e. Юзать обе функции одновременно?

А, хотя сам уже разобрался, знаете ли. Просто checked как атрибут задаёт отметку по умолчанию4 если кто не знает - напишу на всякий случай. Тему можно фтопку.

தீர்வு தேர்ந்தெடுக்கப்பட்டது

It is not an attribute, but a Boolean JavaScript variable and you can't remove it.

Note that if (document.getElementById('autologin').checked = true){} will set that variable always to true.

You probably want this:

function vibor(){
 if (document.getElementById('autologin').checked == true){
   document.getElementById('autologin').checked = false;
   document.getElementById('autologin1').style.backgroundPosition = 'left top'; 
 } else {
   document.getElementById('autologin').checked = true;
   document.getElementById('autologin1').style.backgroundPosition = 'left bottom';
   }
} 

cor-el, thank you! I used this code and don't have a problem. This is checkbox of autologin to forum "Лунная студия" (moon studio) and that looks very beautiful! Again thank you!

You're welcome.