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)