• Get html element from child element name

    I have a list in which there is one active class

    <ul class="tabs clearfix" >
    <li>  
      <a title="abc" href=# >ABC</a> 
    </li>
    <li>
      <a title="xyx" href=# >XYZ</a>
    </li>
    <li class=active > 
      <a title="all" href=# >All</a> 
    </li>
    

    I use local storage to save the tag header, which is then used for loadcontent accordingly. I am having difficulty getting a specific li element when I retrieve the tilite back from local storage. I would like to add an active class to the li element that matches a specific name. Here is the javascript code:

    $(document).ready(function(){
    var tabs = $('.tabs > li');
    if (localStorage.getItem("tabIndex") === null) {
        $( "#content" ).load( "{{url_for('mypage', query=query)}}" );
    }else{
        var lastIndex = localStorage.getItem('tabIndex');
        **Do something to get the specific li element for the title**
        **addclass('active') for the li**
        LoadContent(lastIndex);
    } 
    tabs.on("click", function(){
        tabs.removeClass('active');
        localStorage.setItem('tabIndex', $('a', this).attr('title'));
        $(this).addClass('active');
        var index = $(this).children('a')[0].title;
        LoadContent(index);
    })
    });
    

    I tried $("a[title=lastIndex]").parent().addClass('active');, but this does not seem to work. As always, I really appreciate all the help provided by this site. Thanks

    +4
    source share
    1 answer

    $('a[title="'+ lastIndex +'"]') ,

    : lastIndex = xyz, $('a[title="xyz"]')

    +4

    All Articles