javascript Document word search and count
var input = document.getElementById('typed-text');
input.onkeydown = function (e) {
if (e.keyCode === 13) {
var paragraph = document.getElementById('paragraph');
var result = document.querySelector('.result-output');
var regexp = new RegExp(this.value, 'g');
var textIncludes = paragraph.textContent.match(regexp);
if (result)
result.remove();
paragraph.innerHTML = paragraph.textContent.replace(
regexp,
'<span style="color:red">' + this.value + '</span>');
paragraph.insertAdjacentHTML(
'afterend',
'<span class="result-output" style="display: block; padding: 5px; margin-top: 10px; background: #eee; color: green;">' + (textIncludes ? textIncludes.length : 0) + ' words has been found.</span>');
}
}
<div id="highlights">
<div class="container">
<div class="row">
<div class="col-md-12" id="paragraph">
<p>
text
</p>
</div>
<div class="col-md-12 input-group mt-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">
<i class="fas fa-pencil-alt"></i>
</span>
</div>
<input id="typed-text" type="text" class="form-control" placeholder="Type text">
</div>
</div>
</div>
</div>
Also in JavaScript:
- emmet react self closing tags
- compare two arrays
- can we import jquery library from developer tools
- shadow elevation react native
- create react element with string
- js match img
- Cast to ObjectId failed for value
- NameError: name 'jsonify' is not defined
- javascript increment alphabet
- how can when click buton scrool to another elemtn
- click left event listener javascrip
- crear componente con angular cli
- check if enter key is pressed jquery
- redux get state without store
- javascript uniqie id
- javascript split array into chunks
- get height use js
- redis nodejs
- email collapsible section
- node js interview questions
- java serialize object to json
- js class async constructor
- js trigger click
- schema mongoose