Having a link to a specific DOM element (for example, <mark> ), how can we get the full word containing this element?
For example:
H<mark>ell</mark>o Wor<mark>l</mark>d, and He<mark>llo</mark>, <mark>Pluto</mark>!
I expect to get the following result:
- First
<mark> : Hello - Second:
World - Third:
Hello - Fourth:
Pluto
var $marks = $("mark"); var tests = [ "Hello", "World", "Hello", "Pluto", ]; function getFullWord($elm) {
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> H<mark>ell</mark>o Wor<mark>l</mark>d, and He<mark>llo</mark>, <mark>Pluto</mark>!
javascript jquery
IonicΔ BizΔu
source share