0

i want set names of each tab dynamically using script. I don't know the exact way to do this kindly help me out?Here are my tabs i need to set names dynaically

here is html code:

            <div data-theme="a" data-role="footer" data-position="fixed" data-tap-toggle="false">
            <div class="myNavBar" data-role="navbar" data-iconpos="top" >
                <ul>
                    <li >
                        <a href="#"  id="home_icon"  data-transition="pop" data-theme="a" data-icon="custom" class="ui-btn-active ui-state-persist" >
                            Home
                        </a>
                    </li>
                    <li >
                        <a href="favourites.html"  id="fav_icon" data-transition="pop" data-theme="a" data-icon="custom" >
                            Favorites
                        </a>
                    </li>
                    <li>
                        <a href="Recents.html" id="recent_icon" data-transition="pop" data-theme="a" data-icon="custom" >
                            Offers
                        </a>
                    </li>
                    <li>
                        <a href="Settings.html" id="setting_icon" data-transition="pop" data-theme="a" data-icon="custom" >
                            Settings
                        </a>
                    </li>
                </ul>
            </div>
       </div>
Nomiluks
  • 2,052
  • 5
  • 31
  • 53

3 Answers3

1

Try this.

var i=0,
navNames = ['home_icon', 'fav_icon', 'recent_icon', 'setting_icon'];

$('.myNavBar').find('li').each(function(){
    $(this).children('a').attr('id', navNames[i])
    i++;
});

Fiddle Demo

Try this approach to put text too on navigation bar.

var i=0,
 navNames = {
                'Home': 'home_icon',
                'Favorites':'fav_icon',
                'Offers': 'recent_icon',
                'Settings': 'setting_icon'
            };

$.each(navNames, function(index, value){
    $('.myNavBar').find('li:eq('+i+')')
    .children('a').attr('id', value)
    .end().children('a').text(index);
    i++;
});

Second Demo

Rakesh Kumar
  • 2,705
  • 1
  • 19
  • 33
0

Try this

$('ul li:eq(0) a').text('Your Text') //It will change 1st li text,same way others by 1,2,3

Fiddle

Sridhar R
  • 20,190
  • 6
  • 38
  • 35
0

All above answered ways are right but, in the above solutions icons of tab hide and only it shows updated text. The right way to do this is $($('.ui-btn-text')[0]).html('testing');. It will change the name of first tab Home to testing.

Barnee
  • 3,212
  • 8
  • 41
  • 53
Nomiluks
  • 2,052
  • 5
  • 31
  • 53