How do you code a word in so that when you click it, it defines it...? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

How do you code a word in so that when you click it, it defines it...?

Sorry, I havent coded in such a long time that I forgot a lot of stuff....but ow do you code a word in so that when you click it, it defines it? I would prefer web and java. Thank you!

16th Jul 2018, 11:38 PM
blue
blue - avatar
4 Answers
+ 6
Web and java? Do you mean JavaScript then? If so... This is crude, but it works as what you've described. HTML part... ************************************ <!DOCTYPE <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Define Word</title> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <h1>Click to define word</h1> <ul> <li id="word1">Hippopotamus</li> </ul> <script src="main.js"></script> </body> </html> ************************** And JavaScript ********************* var word1 = document.getElementById("word1"); word1.addEventListener("click", function(){ alert("a large thick-skinned semiaquatic African mammal, with massive jaws and large tusks"); }) ****************************
17th Jul 2018, 2:06 AM
Andrew Brudnak
Andrew Brudnak - avatar
+ 4
I'm trying hard as I can man.... but I can't figure out what you're asking. :D Tell ya what, can you give an example of what it's meant to accomplish instead or rephrase what you're asking? I'll be more than happy to help afterward.
17th Jul 2018, 12:22 AM
Fata1 Err0r
Fata1 Err0r - avatar
+ 4
great job of separating html from javascript Andrew brudnak ! love the javascript event listener! ty for the fine example of best practices
17th Jul 2018, 10:58 AM
Lisa F
Lisa F - avatar
+ 1
Fata1 Err0r , I want to create some apps...such as the bible where there might be hard words that when you click on the word the definition/image pops up....
18th Jul 2018, 3:22 AM
blue
blue - avatar