jquery - Change style based on html content -
i have html fragment looks this:
field status: <span class="field-status">closed</span>
or might this:
field status: <span class="field-status">open</span>
how make closed red , open green based on content. part of larger system of have no control, can adjust html source. think bit of jquery in there if that's best way.
if can change html , css, should have set so,
field status: <span class="field-status closed">closed</span> field status: <span class="field-status open">open</span>
.field-status.closed { color: red; } .field-status.open{ color: green; }
to make work in ie7 , ie8, need make sure you're not in quirks mode.
if can't that, can use jquery add classes.
$('.field-status').each(function(){ var $this = $(this), text = $this.text(); $this.addclass(text.trim().tolowercase()); });
this works in browsers.
Comments
Post a Comment