0

I've been looking into this for some hours now and have read countless posts here on Stackoverflow and through Google. I've also read up on a few PHP methods and am studying up on some Regex but am not sure on the best method. Here's what I'm trying to achieve:

I have some simple title tags in an hgroup like so:

<hgroup>
  <h1>Title</h1>
  <h2>Subtitle</h2>
</hgroup>

Please note, the hgroup may have a class as well.

I need to search my page for the hgroup tag (with the possible class) and add some code on a new line becoming

<hgroup>
  <span>NEW LINE AND TEXT</span> 
  <h1>Title</h1>
  <h2>Subtitle</h2>
</hgroup>

I've found a few solutions to find a class or tag but am not sure how to add a new line of code successfully between.

Mikel
  • 117
  • 11

1 Answers1

2

With jQuery:

$("hgroup") // note this could be the class name: you pass in a CSS selector
  .prepend( $("<span/>").text("New line and text") );

Live example: http://jsfiddle.net/HzY6y/

Simon Boudrias
  • 42,953
  • 16
  • 99
  • 134
  • @Mikel Ward just put your variable in the .text("") – Viscocent May 04 '13 at 04:25
  • Careful there, shouldn't mix javascript and PHP code. This make for unmaintainable code and a lot of headache. If you're doing something, do it correctly. Keep each in their bondaries, PHP generate the page, javascript take care of the interations once the page is served. – Simon Boudrias May 04 '13 at 04:29