js traverse the elements and add attributes

 

<body> 
  <
div ID = "Content" >    < span > learn </ span >   < span > every day </ span >   </ div >
</ body>
<script type="text/javascript">
$(document).ready(function(){
    $("#content>span").each(function(index,item){
        var str = $(item).text();
        if(str.indexOf("好好学习")!=-1){
            $(item).css("color","red");
        }
    });
})
</script>

 

Guess you like

Origin www.cnblogs.com/mjtabu/p/11759785.html