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

方法

参考にした記事 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を使用し、ファイル読み込み時にメソッドが動く様に記述を行った。