I am trying to replace the content of li and tags.
Tried below code.
<html>
<head>Sample</head>
<body>
<a href="#"><input type="checkbox" class="layer-input-filter" name="testname">Test <span class="count">5</span> </a>
<a href="#"><input type="checkbox" class="layer-input-filter" name="testname1">Test1 <span class="count">10</span> </a>
<ul>
<li><a href="#" rel="noopener">Mixed assessment guidelines</a></li>
<li><a href="" target="_blank" rel="noopener">Specimen </a></li>
<li><a href="#" rel="noopener">Plagiarism </a></li>
<li><a href="" target="_blank" rel="noopener">Download </a></li>
<li><a href="#" rel="noopener">Qualification update</a></li>
<li><a href="" target="_blank" rel="noopener">Specimen</a></li>
<li><a href="#" rel="noopener">Exam guide update</a></li>
<li><a href="" target="_blank" rel="noopener">Guide </a></li>
</ul>
<script>
$(document).ready(function($) {
var value = 0.4;
$("body").find('li').each(function (index) {
if ($(this).text() != '') {
var str = $(this).clone().children().remove().end().text();
var newstring = str + str.substring(0, str.length * value);
$(this).text(newstring);
}
});
});
</script>
</body>
</html>
I need to replace the text of every li inside the body. so used above jquery for it. But its not working.
Example :
<li><a href="#" rel="noopener">Plagiarism </a></li>
Should replace as
<li><a href="#" rel="noopener">PlagiarismPlag </a></li>
First four characters of each li text. That is Plag in above example
Can anyone help me with this, please?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…