How to insert an element after another element in JavaScript without using a library?

referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); Where referenceNode is the node you want to put newNode after. If referenceNode is the last child within its parent element, that’s fine, because referenceNode.nextSibling will be null and insertBefore handles that case by adding to the end of the list. So: function insertAfter(newNode, referenceNode) { referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); } You can test it … Read more

Using PHP read word in textarea line by line and insert to mySQL

you can code like: $val=”Veg Tomato Potato Fruits mango banana”; $textAreaVal = $val; $arrVal = explode(PHP_EOL, $textAreaVal); for($i=0; $i < count($arrVal); $i++){ $type=””; $isInIf = false; if($arrVal[i] == ‘Veg’){ $type=”Veg”; }else if($arrVal[i] == ‘Fruits’){ $type=”Fruits”; } if($type != ”){ // your insert query here // insert into tbl(type, name) values(‘$type’, ‘$arrVal[i]’) } }