How do I set an element via jQuery / Javascript?

0
  

I'm doing an integration with a social plugin and am having a problem.

My code:

linkedin : function(self){
  var sett = self.options.buttons.linkedin;
  $(self.element).find('.buttons').append('<div class="button linkedin"><script type="IN/Share" data-url="'+(sett.url !== '' ? sett.url : self.options.url)+'" data-counter="'+sett.counter+'"></script></div>');
  var loading = 0;
  if(typeof window.IN === 'undefined' && loading == 0){
    loading = 1;
    (function() {
      var li = document.createElement('script');li.type = 'text/javascript';li.async = true;
      li.src = '//platform.linkedin.com/in.js'; 
      var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li, s);
    })();
  }
  else{
    window.IN.init();
  }
},

The above code is responsible for creating something like:

<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/Share" data-counter="top"></script>

/ p>

So:

<script src="//platform.linkedin.com/in.js" type="text/javascript">
      lang: pt_BR
</script>
<script type="IN/Share" data-counter="top"></script>
  

Could this adaptation be possible? how?

    
asked by anonymous 20.12.2014 / 00:38

2 answers

4

Set what's inside as the innerHTML (or textContent ) of the tag:

li.innerHTML = 'lang: pt_BR';
    
20.12.2014 / 02:03
1

Not that it's really necessary but since I've been asked to solve the problem with pure JavaScript or jQuery, and I'll be well-off and leave the alternative here too

$( document ).ready( function() {
    
    $( '#div' ).append(

        $( '<script>' ).attr({

          'type':  'text/javascript',
          'src':   '//platform.linkedin.com/in.js',
          'async': 'true'

        }).text( 'lang: pt_BR' )
    )

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="div"></div>
  

You need to Inspect the element and look for the DIV #div to see, since it is a <script> tag

    
20.12.2014 / 21:36