473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

color the line begin with

usafshah
104 100+
In html/css/javascript, is it possible to change the color of the line for which you set certain parameters like if the line begin with # , then change with color of the line blue

example:
================================================
This is normal line
#This line should automatically get blue via javascript or whatever
the next line is again normal line
================================================

I hope you get my point, any help is much appreciated

Thanks.
Apr 9 '08 #1
3 1120
acoder
16,027 Expert Mod 8TB
Yes, this should be possible if you take the text and split using newlines, then check the first character and add spans around the content that needs to be colored blue, then finally write this content back to the content holding element.
Apr 9 '08 #2
usafshah
104 100+
I tried but I couldn't get it working, if you can give an example here as I'm not good at scripting stuff.
Apr 9 '08 #3
acoder
16,027 Expert Mod 8TB
An example to give you an idea:
Expand|Select|Wrap|Line Numbers
  1. <style>
  2. .blue { color: blue; }
  3. </style>
  4. <script>
  5. function colorBlue() {
  6.   var cd = document.getElementById("content");
  7.   var content = cd.innerHTML.split("\n");
  8.   for (i = 0; i < content.length; i++) {
  9.     if (content[i].charAt(0) == "#") {
  10.       content[i] = "<span class='blue'>"+content[i]+"</span>";
  11.     }
  12.   }
  13.   cd.innerHTML = content.join("\n");
  14. }
  15. window.onload = colorBlue;
I've split on the newline, but if you mean a newline in HTML output, you could split on "<br>". I've also assumed a div named "content" - you could change this to document.body.
Apr 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
1
by: Sandesh | last post by:
Hello All, Me saying " has any body come across such error would be underestimating". Well I am getting a very peculiar and unique error "Line 1: Incorrect syntax near 'Actions'." ...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
12
by: robertino | last post by:
Hi all, I've put together a few SPs to produce a BOM (bill of materials) listing, which together use a couple of global temp tables, and return the results from a cursor. Here's the code: ...
24
by: Ground21 | last post by:
Hello. How could I read the whole text file line after line from the end of file? (I want to ~copy~ file) I want to copy file in this way: file 1: a b
1
by: Ruth413 | last post by:
Hello - I am getting the these errors in my sql 2005 generated script. I am stuck with first error. Please help.... Msg 102, Level 15, State 1, Line 3 Incorrect syntax near '('. Msg 319,...
9
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
I want to open a text file and format it into a specific line and then apply color to a specific location of the text and then display it in a RichTextBox after all of this is done. I can do all...
1
by: todWulff | last post by:
Good day folks. Let me open with the statement that I am not a C++/C programmer. The environment that I am programming in is ARMbasic, an embedded BASIC targeted toward ARM-based...
15
by: puzzlecracker | last post by:
What is the quickest way to check that the following: const line; only contains whitespace, in which case to ignore it. something along these lines: isspacedLine(line); Thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.