Home jQuery - making text bold with loop and delay
Reply: 0

jQuery - making text bold with loop and delay

user1282
1#
user1282 Published in July 22, 2018, 8:31 am

I'm trying to create someting like that in jQuery:

var x = 0;

function start(){
    setInterval(function () {return changeText(x++);}, 2000);
}

function changeText(index){
    var words = getTextFromDiv().split("/");
    var result = "";

    for(var i = 0; i < words.length; i++){
        if(i == index)
            words[i] = "<b>" + words[i] + "</b>";

        result += words[i];

        if(i != words.length - 1)
            result += "/";
    }
    document.getElementById("divId").innerHTML = result;
    if(x == words.length){
        x = 0;
    }
}

//get text from element without HTML
function getTextFromDiv() {
    var element = document.getElementById('divId');
    return element.innerText || element.textContent;
}

start();
<div id="divId">
   aaa / bbb / ccc / eee
</div>

I tried to use each loop and delay. But it isn't working. Do you have any idea how to make it?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308703 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO