Sunday 15 March 2015

dom - Need to Merge adjacent HTML nodes based on class name using JavaScript -


I am trying to complete the following tasks.

Say if I

>

By,

  & lt; Div id = 'parent' & gt; & Lt; Span class = 'a' & gt; Good morning & lt; / Span & gt; & Lt; Span class = 'c' & gt; World & lt; / Span & gt; & Lt; / Div & gt;  

I want to merge the adjacent nodes, which have the same class names.

So far there is only one idea that I am comparing loop and orbit through every nodes. But, I am not sure whether this is the only solution or not.

Any idea or 'the path of new perspective' will be very useful :)

Try this type

Similar question:

  $ (document) .ready (function () {var endelement; $ .each ($ ('. ItemRow' ), Function (index, value) {if (index == 0) endearment = $ (this); and ($ .eight ($ (this). Children ('item'), function (I, v) {endelement .append ($ (this));});}}); $ ('end.Product'). Attachments [hrs] [0] .ter HTML; console log (endeavor); console.log ( [0] Kyutr HTML)});  

Of course, this only works through the hardcoding of the classname, so that the classname can be dynamically captured and organized so that we can process it like LoDash or underscore The library has to be used.


No comments:

Post a Comment