Shahzad Ditro Shahzad Ditro - 26 days ago 6
CSS Question

How to give the color to * without using span Tag

I am doing working with WordPress and using event Plus plugin that plugin

is using the form. some field are predefined and some field we can create using

customize functionality.My requirement is I want to show required field * color

red.And I can't use the span tag because it is creating the problem with form

validation message. I just want * should be show in red color. How can I use

CSS for that.

the form is below:-



<form name="regform" class="evrplus_regform" method="post" action="https://manresa-sj.com/evrplus_registration/?" onsubmit="mySubmit.disabled = true;
return validateForm(this)">
<ul>
<li>
<label for="fname">First Name*</label>
<span class="fieldbox"><input type="text" id="fname" name="fname" value=""></span>
</li>
<li>
<label for="lname">Last Name*</label>
<span class="fieldbox"><input type="text" id="lname" name="lname" value=""></span>
</li>
<li>
<label for="email">Email Address*</label>
<span class="fieldbox"><input type="text" id="email" name="email" value=""></span>
</li>
<li title="">
<label for="question-4138">Name and Date of Retreat*</label>
<span class="fieldbox"><input type="text" class="r" id="TEXT_4138" name="TEXT_4138" size="40" title="Name and Date of Retreat*" value="" disabled="disabled"></span>
</li>
<li title="">
<label for="question-4139">Is this is your first retreat there*</label>
<span class="radio"><input id="SINGLE_4139_0" class="r" name="SINGLE_4139" title="Is t" type="radio" value="Yes"> Yes</span><span class="radio"><input id="SINGLE_4139_1" class="r" name="SINGLE_4139" title="Is t" type="radio" value="No"> No</span>
</li>
<li title="">
<label for="question-4140">Title: Mr, Mrs, Ms….</label>
<span class="fieldbox"><input type="text" id="TEXT_4140" name="TEXT_4140" size="40" title="Title: Mr, Mrs, Ms...." value=""></span>
</li>
<li title="">
<label for="question-4141">Nickname</label>
<span class="fieldbox"><input type="text" id="TEXT_4141" name="TEXT_4141" size="40" title="Nickname" value=""></span>
</li>
<li title="">
<label for="question-4142">Suffix: MD, Sr….</label>
<span class="fieldbox"><input type="text" id="TEXT_4142" name="TEXT_4142" size="40" title="Suffix: MD, Sr...." value=""></span>
</li>
<li title="">
<label for="question-4143">Birthday</label>
<span class="fieldbox"><input type="text" id="TEXT_4143" name="TEXT_4143" size="40" title="Birthday" value=""></span>
</li>
<li title="">
<label for="question-4144">Profession</label>
<span class="fieldbox"><input type="text" id="TEXT_4144" name="TEXT_4144" size="40" title="Profession" value=""></span>
</li>
<li title="">
<label for="question-4145">Spouse’s Name</label>
<span class="fieldbox"><input type="text" id="TEXT_4145" name="TEXT_4145" size="40" title="Spouse's Name" value=""></span>
</li>
<li title="">
<label for="question-4146">Parish Name</label>
<span class="fieldbox"><input type="text" id="TEXT_4146" name="TEXT_4146" size="40" title="Parish Name" value=""></span>
</li>
<li title="">
<label for="question-4147">Home Phone*</label>
<span class="fieldbox"><input type="text" class="r" id="TEXT_4147" name="TEXT_4147" size="40" title="Home Phone*" value=""></span>
</li>
<li title="">
<label for="question-4148">Mobile Phone</label>
<span class="fieldbox"><input type="text" id="TEXT_4148" name="TEXT_4148" size="40" title="Mobile Phone" value=""></span>
</li>
<li title="">
<label for="question-4149">Business Phone</label>
<span class="fieldbox"><input type="text" id="TEXT_4149" name="TEXT_4149" size="40" title="Business Phone" value=""></span>
</li>
<li title="">
<label for="question-4150">Contact in case of Emergency</label>
<span class="fieldbox"><input type="text" id="TEXT_4150" name="TEXT_4150" size="40" title="Contact in case of Emergency" value=""></span>
</li>
<li title="">
<label for="question-4151">Relationship to you</label>
<span class="fieldbox"><input type="text" id="TEXT_4151" name="TEXT_4151" size="40" title="Relationship to you" value=""></span>
</li>
<li title="">
<label for="question-4152">Address*</label>
<span class="fieldbox"><input type="text" class="r" id="TEXT_4152" name="TEXT_4152" size="40" title="Address*" value=""></span>
</li>
<li title="">
<label for="question-4153">City*</label>
<span class="fieldbox"><input type="text" class="r" id="TEXT_4153" name="TEXT_4153" size="40" title="City*" value=""></span>
</li>
</ul>
</form>




Answer

You can use jQuery:

  $(document).ready(function(){
    $("label").each(function(){
    var labelValue = $(this).text();
    if(labelValue.includes("*")){
        $(this).addClass("required");
      $(this).text(labelValue.replace("*",""));
    }
  });
});

and css:

.evrplus_regform label.required:after{
  content:"*";
  color:red;
}

Try it yourself here.

Pure css way:

Just add required class to your required label and use css above.

<label for="fname" class="required">First Name</label>
Comments