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

  • Home
  • SEARCH
  • 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 8783779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:54:54+00:00 2026-06-13T20:54:54+00:00

I am trying to make a specific letter: "*" be red in a line

  • 0

I am trying to make a specific letter: "*" be red in a line of JavaScript coding that I am working with.
The following is my original:

function init(){
    var inp = document.getElementsByTagName('input');
    for(var i = 0; i < inp.length; i++) {
        if(inp[i].type == 'text','tel','number', 'email') {
            inp[i].setAttribute('rel',inp[i].defaultValue)
            inp[i].setAttribute('style', 'color: grey;')
            inp[i].onfocus = function() {
                if(this.value == this.getAttribute('rel')) {
                    this.value = '';
                    this.setAttribute('style', 'color: black;')
                } else {
                    return false;
                }
            }

In order to make a specific letter red, would I change it to?

function init(){
    var inp = document.getElementsByTagName('input');
    for(var i = 0; i < inp.length; i++) {
        if(inp[i].type == 'text','tel','number', 'email') {
            inp[i].setAttribute('rel',inp[i].defaultValue)
            inp[i].setAttribute('style', 'color: grey;')
            inp[i].onfocus = function() {
                if(this.value == this.getAttribute('rel')) {
                    this.value = '';
                    this.setAttribute('style', 'color: black;')

                if(this.value == this.getAttribute('*')) {
                    this.setAttribute('style', 'color: red;')

                } else {
                    return false;
                }
            }

How would I achieve this?

  • 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-06-13T20:54:55+00:00Added an answer on June 13, 2026 at 8:54 pm

    … because I am really bored, I ended up doing what you wanted using javascript.

    It uses Mootools, but it should provide enough inspiration for you to recreate it using jQuery if you so desire.

    function reposition() {
        var position = inputEl.getPosition();
        var occludeLabel = inputEl.value;
        occludeLabel = occludeLabel.replace(/\*/g, '<span class="red">*</span>', 'g');
        occludeEl.setStyles({
            top: position.y + 1,
            left: position.x + 1
        });
        occludeEl.set('html', occludeLabel);
    }
    

    Basically, every time you blur the input, a div containing the input box’s value is placed over the input box, occluding the text. I ran a simple .replace() to replace all asterisks with a span that would turn its contents red.

    Please see this jsfiddle for all of the code: http://jsfiddle.net/eTEvQ/2/

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

Sidebar

Related Questions

I'm trying make a function that lists all subkeys of a specific (windows registry)
I'm trying to make a function that recursively builds a path for a specific
I am trying to make a program in Java that checks for three specific
I'm trying to make a button in Flash Builder 4.5 that is multi-lined (specific
i'm trying to make a program that inserts data into specific places in existing
I'm trying to make a query that selects all messages from a specific user
I'm trying to make an application that checks if this specific application is running,
So i am trying to make a game that will load a specific XIB
I'm trying to make a specific control smaller, without making its content smaller.. If
I am trying to make software install to a specific directory. I found several

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.