Mahedi Sabuj Mahedi Sabuj - 1 year ago 97
Javascript Question

Get Inner Text from DIV


<div id="country">

<div id="capital">

  1. From
    , I want to get Bangladesh

  2. From
    , I want to get Dhaka

How can I achieve this?

Answer Source

Try if this works


.clone() clones the selected element.

.children() selects the children from the cloned element

.remove() removes the previously selected children

.end() selects the selected element again

.text() gets the text from the element without children