var nodes = div.querySelectorAll('[move_id]'); var first = nodes[0]; var last = nodes[nodes.length- 1];