I have the following function:
// Change nav item in header in order to display it shorter
function toggleInnerHtml(){
$('#header .top ul li span, .banner nav.company li a span').each(function(index, value){
var nav_item_text = value.innerHTML;
for (i = 0; i < nav_item_text.length; i++) {
if(nav_item_text == 'Häufig gestellte Fragen (FAQ) - Übersicht' ){
nav_item_text = 'FAQ';
this.innerHTML = nav_item_text;
}
}
});
}
toggleInnerHtml();
The function goes into the header of my page and changes the name of the menu item "Häufig gestellte Fragen (FAQ) - Übersicht" to "FAQ". However, this function works too slowly, so "Häufig gestellte Fragen (FAQ) - Übersicht" always appears just before "FAQ" appears.
Is there a way to optimize my function so that this error no longer occurs? Unfortunately I have to solve it this way because my CMS generates the menu items based on the page names within the CMS.
ifrom the for loop, so you can just omit this linefor (i = 0; i < nav_item_text.length; i++) {nav_item_textand set innerHTML of your element at every iteration... Why do you do this? Simply remove this for loop and you'll be way better.