wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Highlight words on my webpage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Highlight words on my webpage" Watch "Highlight words on my webpage" New topic
Author

Highlight words on my webpage

Stef jansen
Greenhorn

Joined: Dec 25, 2009
Posts: 5
Hello,
I want to make a link on my webpage.
When this link is activated then some words on my page are highlighted. There must not be jumped to this words.
Can someone help me with this?

Bey.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Schoolbord jansen wrote:There must not be jumped to this words.

I'm not sure what you mean by this.

But changing the rendition of the words is as easy as adjusting the CSS in the click handler. What part are you having problems with?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stef jansen
Greenhorn

Joined: Dec 25, 2009
Posts: 5
I don't want to highlight te same word that is clicked in with the mouse.
I want other words become highlighted, when is clicked on one word/link.

I you understand it now? (my english is not very good)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

"schoolbord jansen", please check your private messages for an important administrative matter.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Schoolbord jansen wrote:I you understand it now?

I understood it to begin with. The answer remains the same. In the click handler, apply a CSS class that defines the "hightlight" to the words you want highlighted.
Stef jansen
Greenhorn

Joined: Dec 25, 2009
Posts: 5
Hello
Can you help me a little bit more specific?, because i still do not know how to do it.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Jansen did you check your private messages??

If you know basic HTML, CSS and Javascript, then this must not be hard for you. Have you tried anything yet??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Stef jansen
Greenhorn

Joined: Dec 25, 2009
Posts: 5
Yes, i did check my private messages and hope i corrected my name ok.

What i tried is the following:

I added this to the style sheet:
.hilite:target {color: #ff0000}
.hilite {color: #000000}

I added this as text:
<p>This is a <span class="hilite" id="text1">test.</span></p>

And to highlight the word "test" i added this:
<a href="#text1">Select here</a>

Then it works, but only in Firofox and not in Internet Explorer. Can someone help me with this?
I also want to highlight more than one word when i click on the link, so i copied the <a href="#text1">Select here</a>
but then not both lines are highlighted. How can i highlight more then 1 line?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

:target is a CSS3 pseudo-class that I do not believe that IE supports.
Stef jansen
Greenhorn

Joined: Dec 25, 2009
Posts: 5
@Bear thanks for your post, so i think i cannot use the "target" function i think.

I now tried it this way:
========================================================
<script language="JavaScript" type="text/javascript">
function highl(a){
document.getElementById(a).style.background = "#FFFFBF";
document.getElementById(a).style.padding = "0px";
}
</script>
=========================================================
<p><a href="#hi" onclick="highl('hi');">Select</a></p>
=========================================================
<span id="hi">Test1</span>
=========================================================

This works in IE and FF. But i can only select one word now, and i want to select more words.
How can i do this?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

You've already been give the clue: assign a CSS class to each word that you want highlighted.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Highlight words on my webpage
 
Similar Threads
Common phone interview questions ?
How to open Small Window
All about static methods
JButton
How to link JFreeChart with JSP