特定のURLの時のみIDにclassを付与するjs特定のURLの時のみIDにclassを付与するjsです。<script type="text/javascript">hideClass = location.href.indexOf("xxxxxxx"); if ( hideClass !== -1 ) { document.getElementById("btn").className = "active";}</script>※URLに「xxxxxxx」がある時のみ、id="btn"にactiveというclassを付与。10Aug2019コピペjQuery
スマホの場合のみtelリンクを有効にするスマホの場合のみtelリンクを有効にするjsです。if (navigator.userAgent.match(/(iPhone|iPad|iPod|Android)/)) { $(function() { $('.tel_link').each(function() { var str = $(this).html(); if ($(this).children().is('img')) { $(this).html($('<a>').attr('href', 'tel:' + $(this).children().attr('alt').replace(/-/g, '')).a...08Aug2019コピペjQuery
特定のクラスに連番でidを付与要素それぞれの色を変えたい時など、特定のクラスに連番でidを振るjQueryです。もちろん、jQuery本体は読み込んだ状態で書いてくださいね。<script>$(function(){ $('.example').each(function(i){ $(this).attr('id','category' + (i+1)); });});</script>※ li class="example"にid="category1"から連番で付与。クラス名、id名は自由に変えてください。06Aug2019jQuery