Jump to content

Style Based On Innerhtml?


pizzaguy

Recommended Posts

Is it possible to base an element's style on it's innerHTML? I tried:

h2[innerhtml=blank]{	color: #ff0000;}

but that didn't work. If it would help, what i'm trying to do is style and h2 based on the text that is in side it, so if the text is "blank" it would be styled differently than other h2 tags.

<h2>blank</h2>

Link to comment
Share on other sites

You're mixing apples and oranges. innerHTML is a DOM property, accessible through JavaScript. It doesn't play with CSS. The square [brackets] you're using are for attribute selectors. You could specifiy the value of an HTML attribute like href or name. But you cannot specify the text content of an element.If you are generating the innerHTML on the fly, in JavaScript or server-side, you could set a className at that time.

Link to comment
Share on other sites

You're mixing apples and oranges. innerHTML is a DOM property, accessible through JavaScript. It doesn't play with CSS. The square [brackets] you're using are for attribute selectors. You could specifiy the value of an HTML attribute like href or name. But you cannot specify the text content of an element.If you are generating the innerHTML on the fly, in JavaScript or server-side, you could set a className at that time.
Thanks, I knew it was DOM, but I was just hoping there would be an equivalent value of it in CSS. I thought about using the server-side class modification, but I don't know how given the situation. I'm making this for widgets in a Wordpress theme, and I don't know how to make wordpress put a class in, based on the title and still put a title in normally.
if ( function_exists('register_sidebar') )	register_sidebar(array(	'name' => 'sidebar',	'before_widget' => '<div class="sidebar-box">',	'after_widget' => '</div>',	'before_title' => '<h2>',	'after_title' => '</h2>',));

Side note: Should I post a new topic in PHP now, or can I just leave this here?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...