Insert JQuery between Label tags?

sandshakimi
sandshakimi used Ask the Experts™
on
Goal:  Color the asterisk red.

Here's the current markup:

<label for="edit-field-deliverable3-und-other">Demonstration Name *</label>


Here's what I'm trying to achieve:

<label for="edit-field-deliverable3-und-other">Demonstration Name <span style='color: red'>*</span></label>



Note: The code is autogenerated so I don't have the choice of manually inserting code into the label tag.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Awarded 2012
Commented:
Hi,
assuming you have no other HTML Markup in the labels, the following will work:
$(document).ready(function () {
   $("label").each(function () {
       $(this).html($(this).text().replace(/\*$/,"<span style='color:red'> *</span>"));
   });
});

Open in new window

Live sample:
http://jsfiddle.net/EE_RainerJ/y3mrtfxx/

HTH
Rainer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial