Jump to content
dodgeitorelse3

set partial text color via javascript

Recommended Posts

Posted (edited)

I have been working on this code for quite some time

var ul = top.document.getElementById("sub-menu");   
    var li = top.document.createElement("li");
    var a = document.createElement('a');
	var stradd = " (tours.ini not found)";
	var linkText = document.createTextNode("<?php echo $loguname;?>"+stradd);
	a.appendChild(linkText);
	a.href = "tours_U/<?php echo $loguname;?>/tours.ini";
	li.appendChild(a);
	li.setAttribute("name", "tours_download[]");
	li.setAttribute("id", "li<?php echo $loguname;?>");
	li.style.fontSize="12px";
	ul.appendChild(li);

what I am having trouble doing is setting the color of stradd variable. I cannot figure out how to access just that part to make the font color white (parenthesis included).

 

Where can I find documentation to help me sort this out?

Edited by dodgeitorelse3

Share this post


Link to post
Share on other sites

my bad I meant to put this in the javascript forum, can an admin please move it?

Share this post


Link to post
Share on other sites

You can't just randomly color a piece of text. What you can do however, is put a span around that section, and style the span.

Share this post


Link to post
Share on other sites

Debugging your code & find error in each line. Check your text line in debugging a.appendChild(linkText);

Share this post


Link to post
Share on other sites

thank you gizmola, no idea why I didnt think of that.

@HemendraSingh, Thank you. I will have to learn how to debug javascript and then I will see what you were getting at for that line of code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.