JSFiddle - React, Tailwind, and code Playground
HTML
<div id="1" data-go-to="1">1</div>
<div id="3" data-go-to="2">null</div>
<div id="2" data-go-to="">null1</div>
<div id="4" data-go-to="">null2</div>
<br />
<div id="log"></div>
JavaScript
// All the elements
$(':not([data-go-to=""])').each(function(){
$('#log').append( $(this).attr('id') + '<br>' );
});