Dynamically assign class to paragraph

Posted by user1684300 on Stack Overflow See other posts from Stack Overflow or by user1684300
Published on 2012-09-19T21:36:40Z Indexed on 2012/09/19 21:37 UTC
Read the original article Hit count: 153

Filed under:
|
|
|

How do you assign a class dynamically to a paragraph (via javascript/CSS) IF the paragraph contains the wording "Time Recorded:"?

You'll notice that I have manually assigned the

with class . However, I'd like to dynamically assign this class to any

tag which contain the words "Time Recorded:".

Please can you help ?

Thank you. PLJ

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script type="text/javascript">
if (document.all || document.getElementById){ //if IE4 or NS6+
document.write('<style type="text/css">')
document.write('.dyncontent{display:none;}')
document.write('</style>')
}
</script>
<div class="right">
<ul>
<li class="say agent public">
<p>Description line 1</p>
<p class="dyncontent">Time Recorded: 5MIN(S)</p>
<p>Another description line</p>
</li>
</ul>
</div>
</body>
</html>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html