Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6847279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:43:33+00:00 2026-05-27T00:43:33+00:00

Having colorized source code (by GeSHi or tool like http://tohtml.com ) like this: <pre

  • 0

Having colorized source code (by GeSHi or tool like http://tohtml.com) like this:

<pre style='color:#000000;background:#ffffff;'>
<ol>
<li><a href="#1"><span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '>&lt;</span><span style='color:#40015a; '>iostream</span><span style='color:#800000; '>></span></a></li>
<li> </li>
<li><span style='color:#800000; font-weight:bold; '>using</span> <span style='color:#800000; font-weight:bold; '>namespace</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>;</span></li></li>
<li> </li>
<li><span style='color:#800000; font-weight:bold; '>int</span> <span style='color:#400000; '>main</span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span></li>
<li> </li>
<li>    <span style='color:#800000; font-weight:bold; '>int</span> intNum <span style='color:#808030; '>=</span> <span style='color:#008c00; '>0</span><span style='color:#800080; '>;</span></li>
<li>    </li>
<li>    <span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> intNum<span style='color:#800080; '>;</span></li>
<li>    <span style='color:#800000; font-weight:bold; '>while</span> <span style='color:#808030; '>(</span>intNum <span style='color:#808030; '>!</span><span style='color:#808030; '>=</span> <span style='color:#008c00; '>42</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span></li>
<li>        <span style='color:#603000; '>cout</span> <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> intNum <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span></li>
<li>        <span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> intNum<span style='color:#800080; '>;</span></li>
<li>    <span style='color:#800080; '>}</span></li>
<li> </li>
<li>    <span style='color:#800000; font-weight:bold; '>return</span> <span style='color:#008c00; '>0</span><span style='color:#800080; '>;</span></li>
<li> </li>
<li><span style='color:#800080; '>}</span></li>
</ol>
</pre>

screenshot:

enter image description here

I want to create mechanism which will colorize clicked by user line. I know that I need to change background-color of specific li element. I wondering how can I achieve that.

Is this will be ok, to add to each line:

<liid='id1'><a href="javascript:color('1')">...</a></li>

<liid='id2'><a href="javascript:color('2')">...</a></li>

  • Is it necessary, to add unique id to each li element?
  • Is it possible to pass to JS function some kind of id/”this pointer”/whatever what will point JS function, which element should be changed?

EDIT:

One more requirement: after all, I need to pass information about which line was clicked, to URL. I want to do that without reloading a webpage, so I want to add something like #NUMBER_OF_CLICKED_LINE

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:43:33+00:00Added an answer on May 27, 2026 at 12:43 am

    One approach to simply highlight the list elements is to use:

    var ol = document.getElementsByTagName('ol')[0];
    var lis = ol.getElementsByTagName('li');
    var highlight = '#ffa';
    
    for (i=0;i<lis.length;i++){
        lis[i].onclick = function(){
            this.style.backgroundColor = highlight;
        };  
    }
    

    JS Fiddle demo.

    With regards to the need for the clicked-line to be appended to the URL as a hash (something which can’t be easily demonstrated by JS Fiddle):

    var ol = document.getElementsByTagName('ol')[0];
    var lis = ol.getElementsByTagName('li');
    var highlight = '#ffa';
    
    for (i=0;i<lis.length;i++){
            lis[i].setAttribute('data-Index',i);
        lis[i].onclick = function(){
            this.style.backgroundColor = highlight;
            document.location.hash = 'line=' + this.getAttribute('data-index');
        };  
    }
    

    JS Fiddle demo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having already read a number of articles on this here is the code I've
Having a heckuva time with this one, though I feel I'm missing something obvious.
Having a problem getting a TreeView control to display node images. The code below
Having programmed through emacs and vi for years and years at this point, I
Having this route: map.foo 'foo/*path', :controller => 'foo', :action => 'index' I have the
I'm having trouble creating this design. The #container should be centered, with it's two
I can't seem to find any examples of this having been done anywhere on
I am having tough time figure out how to change background color of jQuery
Hey, I am guessing that this is probably fairly trivial, but I am having
Having a spot of trouble with the following code. The method NextIPID() should simply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.