I want to target the first two words of a paragraph using javascript and change their size.
for example:
<p>My name is muhammad hamd</p>
Here I just want to target ‘My name’, the first two words of the p
tag, and change their size.
I want to target the first two words of a paragraph using javascript and change their size.
for example:
<p>My name is muhammad hamd</p>
Here I just want to target ‘My name’, the first two words of the p
tag, and change their size.
2
Answers
See comments inline:
The steps can be combined for more concise code:
Extract specific words from element
You need to get the element
p
, get the string and useslice()-method
to get what you want.