https://i.sstatic.net/Asi5r.pngI am currently working on a page where users can click on a word and receive a small suggestion box (like a tiny popup) to choose synonyms they prefer.
Although I believe this can be achieved with JavaScript, I haven't come across any clear examples of how to implement it.
The HTML code snippet is provided below:
Original:
I <b class="synonyms" style="color:black;"
title="love|really like|really love">like</b> apples.
The desired result should look like this (after a user selects a synonym):
I <b>{like|love}</b> apples.
For instance, when the user clicks on "like" in the sentence "I like apples," a small suggestion box should appear with various options to choose from (such as love, really like, really love).
The final output would include the original text along with the user's chosen synonym.
This example showcases how it can be implemented in JavaScript. However, I'm unsure if it's possible to select specific words (since there could be multiple words in a sentence) and customize the appearance of the suggestion box by adding a list of clickable words for selection.
<!DOCTYPE html>
<html>
<body>
<p>I <b id="demo">like</b> apples.</p>
<button onclick="choose()">Try it</button>
<script>
function choose() {
var synonym = prompt("Choose synonyms:", "like");
if (synonym != null) {
document.getElementById("demo").innerHTML =
"{" + "like" + "|" + synonym + "}";
}
}
</script>
</body>
</html>