1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Javascriptでタグの属性(classやstyle)を指定して削除する方法

Posted at

方法

参考にした記事
https://www.javadrive.jp/javascript/dom/index3.html
https://www.javadrive.jp/javascript/dom/index18.html
https://www.tam-tam.co.jp/tipsnote/javascript/post601.html

Jqueryの場合

 $(function() {
   $("span").removeAttr("style");
   $("span").removeAttr("width");
});

Vanilla JSの場合

<script>
/*ページ読み込み時にspanタグに埋め込まれたstyle="〇〇px"を削除するメソッド*/
window.onload = function(){
document.querySelector('.select2').removeAttribute('style');
}
</script>

ポイント

Vanilla JSでの実装時はJqueryと異なり、window.onlaoadを使用し、ファイル読み込み時にメソッドが動く様に記述を行った。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?