javascript - Remove class completely with MooTools - Stack Overflow

This post is linked to my previous one. I was able thanks to Pointy's answer to use properly Remov

This post is linked to my previous one.

I was able thanks to Pointy's answer to use properly RemoveClass with MooTools but unfortunately I still have a problem : even after removing the class from the HTML element the HTML element still has an empty class (class="").

I'm wondering if there's a way to avoid this and to remove pletely the class.

my code :

<script type="text/javascript">
  window.addEvent('domready', function(){
    $('votconj').addEvent('click', function() {
      $('first_name_conjoint').addClass("validate['required','nodigit']");
      $('last_name_conjoint').addClass("validate['required','nodigit']");
      $('jj_conjoint').addClass("validate['required']");
      $('mm_conjoint').addClass("validate['required']");
      $('aaaa_conjoint').addClass("validate['required']");
      $('conjoint_regime').addClass("validate['required']");
      new FormCheck('formulaire');
    });

    $('votconj_no').addEvent('click', function() {
      $('first_name_conjoint').removeClass("validate\\['required','nodigit'\\]");
      $('first_name_conjoint').removeProperty('class');
      $('last_name_conjoint').removeClass("validate\\['required','nodigit'\\]");
      $('last_name_conjoint').removeProperty('class');
      $('jj_conjoint').removeClass("validate\\['required'\\]");
      $('jj_conjoint').removeProperty('class');
      $('mm_conjoint').removeClass("validate\\['required'\\]");
      $('mm_conjoint').removeProperty('class');
      $('aaaa_conjoint').removeClass("validate\\['required'\\]");
      $('aaaa_conjoint').removeProperty('class');
      $('conjoint_regime').removeClass("validate\\['required'\\]");
      $('conjoint_regime').removeProperty('class');
      new FormCheck('formulaire');
    });

    new FormCheck('formulaire');
});
</script>

radio button code

<label>Conjoint :</label>
    <input type="radio" name="votconj" id="votconj" value="oui" onclick="affich_conj();">oui
    <input type="radio" name="votconj" id="votconj_no" value="non" checked="checked" onclick="affich_conj();">non

This post is linked to my previous one.

I was able thanks to Pointy's answer to use properly RemoveClass with MooTools but unfortunately I still have a problem : even after removing the class from the HTML element the HTML element still has an empty class (class="").

I'm wondering if there's a way to avoid this and to remove pletely the class.

my code :

<script type="text/javascript">
  window.addEvent('domready', function(){
    $('votconj').addEvent('click', function() {
      $('first_name_conjoint').addClass("validate['required','nodigit']");
      $('last_name_conjoint').addClass("validate['required','nodigit']");
      $('jj_conjoint').addClass("validate['required']");
      $('mm_conjoint').addClass("validate['required']");
      $('aaaa_conjoint').addClass("validate['required']");
      $('conjoint_regime').addClass("validate['required']");
      new FormCheck('formulaire');
    });

    $('votconj_no').addEvent('click', function() {
      $('first_name_conjoint').removeClass("validate\\['required','nodigit'\\]");
      $('first_name_conjoint').removeProperty('class');
      $('last_name_conjoint').removeClass("validate\\['required','nodigit'\\]");
      $('last_name_conjoint').removeProperty('class');
      $('jj_conjoint').removeClass("validate\\['required'\\]");
      $('jj_conjoint').removeProperty('class');
      $('mm_conjoint').removeClass("validate\\['required'\\]");
      $('mm_conjoint').removeProperty('class');
      $('aaaa_conjoint').removeClass("validate\\['required'\\]");
      $('aaaa_conjoint').removeProperty('class');
      $('conjoint_regime').removeClass("validate\\['required'\\]");
      $('conjoint_regime').removeProperty('class');
      new FormCheck('formulaire');
    });

    new FormCheck('formulaire');
});
</script>

radio button code

<label>Conjoint :</label>
    <input type="radio" name="votconj" id="votconj" value="oui" onclick="affich_conj();">oui
    <input type="radio" name="votconj" id="votconj_no" value="non" checked="checked" onclick="affich_conj();">non
Share Improve this question edited May 23, 2017 at 11:47 CommunityBot 11 silver badge asked Aug 22, 2011 at 14:56 BrunoBruno 9,10713 gold badges40 silver badges55 bronze badges 4
  • May I ask why you want this? Having class="" isn't harmful in any way. – Luwe Commented Aug 22, 2011 at 17:34
  • @Luwe The problem is that my code is calling another page to check the form and that each time an element of the form has an attribute class the form can't be submitted. – Bruno Commented Aug 23, 2011 at 8:03
  • Hmm weird... Anyway, I've added my answer below. – Luwe Commented Aug 23, 2011 at 8:21
  • Thanks everyone for answering ! – Bruno Commented Aug 23, 2011 at 8:35
Add a ment  | 

2 Answers 2

Reset to default 5

Use removeAttribute provided by JavaScript itself. It will pletely erase the attribute from the tag:

<a href="" class="foo" id="link">Hay</a>

<script>
var link = $('link');
link.removeAttribute('class');
console.log(link);  // <a id="link" href="">
</script>

Example: http://jsfiddle/LDBUy/

You should be able to use the .removeProperty() method to remove the class attribute.

http://mootools/docs/core/Element/Element#Element:removeProperty

Their example:

HTML

<a id="myAnchor" href="#" onmousedown="alert('click');"></a>

JavaScript

//Eww... inline JavaScript is bad! Let's get rid of it.
$('myAnchor').removeProperty('onmousedown');

Resulting HTML

<a id="myAnchor" href="#"></a>

Just swap 'onmousedown' for 'class' in your own code and you should be golden.

EDIT: I updated the jsfiddle from your other question with an example of this (removing the red color from the header) and it works fine. Can you post more of your code to see if the problem is elsewhere?

http://jsfiddle/FrT6V/1/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745221520a4617271.html

相关推荐

  • javascript - Remove class completely with MooTools - Stack Overflow

    This post is linked to my previous one. I was able thanks to Pointy's answer to use properly Remov

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信