ruby - Moving a node as the first child of another node -


i have document:

<html>  <head>    <style>some styles<style>  </head>  <body>    <h1>header</h1>    <table>table content</table>    <div>some text</div>  </body> </a> 

the below code moves <style> tag below <div> in <body>:

  style  = @doc.at_css "style"   body = @doc.at_css "body"   style.parent = body 

is there way move <style> above <h1>?

finding first child of body , adding style tag previous sibling first child solves problem.

  style  = @doc.at_css "style"   body = @doc.at_css "body"   style.parent = body    first_child = body.first_element_child   first_child.add_previous_sibling(style) 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -