1

What I want to do is that I want to create an online bookmarking app for my project. I want to select an element or a paragraph or a text from a HTML template,want to assign a specific color to the selected part of the template, then store it in database with the current user, selected color and current url and when next time the user who selected the texts visits the same page the same texts appears in the same color the user chosen for those.

For example: I have a Template where I have some paragraphs and I select a word named Java Script from the second paragraph. The word java script is repeated there.

JavaScript was originally developed by Brendan Eich, while working for Netscape   
Communications Corporation. While competing with Microsoft for user adoption of web  
technologies and platforms, Netscape considered their client-server offering a
distributed OS with a portable version of Sun Microsystems' Java providing an
environment in which applets could be run.

JavaScript was originally developed by Brendan Eich, while working for Netscape
Communications Corporation. While competing with Microsoft for user adoption of web
technologies and platforms, Netscape considered their client-server offering a
distributed OS with a portable version of Sun Microsystems' Java providing an
environment in which applets could be run.

JavaScript was originally developed by Brendan Eich, while working for Netscape 
Communications Corporation. While competing with Microsoft for user adoption of web
technologies and platforms, Netscape considered their client-server offering a
distributed OS with a portable version of Sun Microsystems' Java providing an
environment in which applets could be run.

Can I somehow find out that which java script word I selected. Does DOM provide such manipulation that from which paragraph I selected a word? Help will be appreciated.

Hogan
  • 69,564
  • 10
  • 76
  • 117
Sajid Ahmad
  • 1,124
  • 4
  • 18
  • 40

1 Answers1

1

You can refer to the answers on this StackOverflow question to learn how to get the range of a selected text. Then, using the startOffset and endOffset Range properties, you can save in the database the start and end indexes of the selected text so in the future you re-select this text and create a new styled DOM node with it, having some colored background or something like that.

Community
  • 1
  • 1
Roberto Linares
  • 2,215
  • 3
  • 23
  • 35