How to change color of letter on mouse hover in JavaScript

后端 未结 3 464
长发绾君心
长发绾君心 2020-12-31 15:54

This is my code:



        
3条回答
  •  盖世英雄少女心
    2020-12-31 16:04

    You can first create a new HTML content using for each character in

    and then replace the HTML of

    with that HTML. Now, when you hover over each character then the color of that character changes to orange

    $(document).ready(function(){
      var letters = $('p').text();
      var nHTML = '';
      for(var letter of letters) {
        nHTML+=""+letter+"";
      }
      $('p').html(nHTML);
    })
    .x:hover {
      color: orange;
    }
    
    

    Hello World!

提交回复
热议问题