/    Sign up×
Community /Pin to ProfileBookmark

Hi,

I am trying to find text in a document using TextRange Object.
After I do:
docrng = document.body.createTextRange(), I want to find, all the paragraphs selected by the user. I have created another range for holding selected text. This is called
rng = document.selection.createRange();
I hold the selected string:
mystr = rng.text;
The paragraphs in mystr are stored in any array called
subStrings[] by finding new lines and splitting the text.

If I select any one para on a document, then docrng.findText(subSrrings[0]) will return true. But if I select 2 para’s, then i have: subStrings[0] and subStrings[1].

If I pass docrng.findText(subSrrings[0]) , then it is returning false! But for docrng.findText(subSrrings[1]) it returns true.

Therefore whenever I select more than one para docrng somehow knows that there is a new line and hence it is just returning true for last paragraph only.

Can someone tell me how to solve this?
I want findText() to return true for multiple paragraph selection.
thanks in advance.

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @gulabi1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...