-2

i am new learner to JavaScript. I have lot of try for inser a span tag after input element. I can do it by jQuery ,But i want to convert it JavaScript. please tell me anyone for my problem. This is my jQuery code i want to same result by JavaScript

jQuery(document).ready(function(){
    jQuery('#selector_id').after('<span class="arrow"></span>');
});
Angel Politis
  • 10,955
  • 14
  • 48
  • 66
shaddam
  • 1
  • 4
  • 3
    Possible duplicate of [How to insert an element after another element in JavaScript without using a library?](https://stackoverflow.com/questions/4793604/how-to-insert-an-element-after-another-element-in-javascript-without-using-a-lib) – ardi4n Jan 28 '18 at 17:30

1 Answers1

0

Welcome to Stack Overflow. When asking a question in future, make sure to show some evidence (usually code) that you've attempted to answer your question before asking it here, as that'll usually help the answerer.

Your code could be translated by replacing the jQuery(selector) syntax with getElementById(), and insertAdjacentHtml() instead of after:

document.getElementById('selector_id')
  .insertAdjacentHTML('afterend', '<span class="arrow"></span>');

There's not really a suitable replacement for $(document).ready(), just make sure to have your script tags at the end of your HTML before the closing </body> tag.

Take a look at http://youmightnotneedjquery.com/ - it's a great resource for translating from jQuery to vanilla JS.

Angel Politis
  • 10,955
  • 14
  • 48
  • 66
Ben Kolya Mansley
  • 1,768
  • 16
  • 24