LoginSignup
2
2

More than 5 years have passed since last update.

JQuery id名でふり分けて処理

Last updated at Posted at 2014-11-12

1)サイドメニューのlistタグ内をeachで回して処理
2)サイドメニューのlistタグのidを取得
3)取得したid名(文字列)が「undefined」の場合、return false; でブレイク
4)それ以外の場合、console.log('bbbb'); を返す
※typeof演算子について
・javascriptの演算子
・値には数値や文字列、オブジェクトなどの値を指定します。
・参考URL:http://www.ajaxtower.jp/js/ope/index15.html

JQuery
$(function(){

    /*======== 繰り返し処理 ========*/
    $('#sidr ul li').each(function(){
        /*#sidr ul li のid名を取得*/
        var menuName = $(this).attr('id');
        /*#取得したid名の型が「undefined」の時*/
        if(typeof menuName == 'undefined'){
            // return false;
            console.log('aaaa');
        }else {
            console.log('bbbb');
        }

    });
    /*======== //繰り返し処理 ========*/

});
2
2
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
2
2