0

Hello friends i would l like to know how you can make an alert that contain only letter "t" from <p>student</p>

Web

25th Feb 2022, 7:50 PM
Beam Rule🌟🌟🌟Emma 😇
Beam Rule🌟🌟🌟Emma 😇 - avatar
8 Réponses
+ 2
Add an id to p. const el = document.getElementById(id); const text = el.textContent; alert(text[text.indexOf('t')])
27th Feb 2022, 7:18 PM
Happy Coder
Happy Coder - avatar
+ 1
Yes thank you very much
27th Feb 2022, 10:31 AM
Beam Rule🌟🌟🌟Emma 😇
Beam Rule🌟🌟🌟Emma 😇 - avatar
0
You can select p using querySelector("p"), this will work if you have only one paragraph on your page, if you have many, you can add id to paragraph and select that id. Then you can use elem.innerText() to access value "student" from paragraph, where "elem" is element you selected. Then you can find "t" but student have 2 "t" so i dont know what "t" you will look for, you can loop trought string in this case "student" and look for letter "t", than if you find assign it to variable You can use alert() to output this value
25th Feb 2022, 9:55 PM
PanicS
PanicS - avatar
25th Feb 2022, 9:57 PM
PanicS
PanicS - avatar
0
Help me with example
26th Feb 2022, 11:31 AM
Beam Rule🌟🌟🌟Emma 😇
Beam Rule🌟🌟🌟Emma 😇 - avatar
0
I just counted letter "t" of word student, you can replace this word with any another and see how counter change. I do this because i dont understand what you exualy try to do You have comments what explain every line of code. I used js6 syntax, but you can replace it. https://code.sololearn.com/WUHP5b2VtqeE/?ref=app
26th Feb 2022, 3:44 PM
PanicS
PanicS - avatar
0
wow it works perfect Then how to make an alert for only letter 'u' from word 'student'
27th Feb 2022, 4:44 AM
Beam Rule🌟🌟🌟Emma 😇
Beam Rule🌟🌟🌟Emma 😇 - avatar
0
Check my code again, i set code to alert any letter "u" in student word. Try adding more letter "u" and you will see more then 1 alert, it will alert every letter now. https://code.sololearn.com/WUHP5b2VtqeE/?ref=app
27th Feb 2022, 10:21 AM
PanicS
PanicS - avatar