I'm trying to replace an HTML element i get via it's index, I'm trying this but it won't work:
<div class="results">
<div id="61">Result 1 content</div>
<div id="8762">Result 2 content</div>
<div id="234">Result 3 content</div>
</div>
<script>
var index = 0;
var html = '<div id="243">Result 1 content</div>';
var element = $('.results').get(index);
element.replaceWith(html);
</script>
how can I replace an entire HTML element by getting it by it's index?
:P(Use a function wrapper, for crying out loud.)eachor viafordepending by the situation, sometimes i get a list of results viaJSONand i need to replace the elements starting by the 0 to the ##. In other cases i just need to update them in runtime..resultselement, if it is not or if you need help adapting the function to work with your use case give a holler.get()will get the native DOM element, which does'nt have a replaceWith method as it's not a jQuery object.