I
I
iegor2015-10-05 05:29:19
JavaScript
iegor, 2015-10-05 05:29:19

How to remove an attribute and then put it back?

You need to do a sequence of actions when you click on the button: remove all attributes from certain objects, add an attribute associated with the clicked one and run a script. Here is my code that I think should do it:

$('.push').click(function(){
    $('.del').removeAttr('id');
    this.next('div').children('.del').setattr('id', 'disqus_thread');
    var disqus_shortname = 'allfreecourses';
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
})

But he doesn't do anything.
P / S In general, the essence of the script should be in loading the diskus to the desired post on the page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-10-05
@iegor

  • First, the event handler context is passed a regular element, not a jQuery object.
  • Secondly, there is no seattr method , there is attr .
  • Thirdly, for what purpose is the closure used ??? For fun?
$('.push').click(function(){
    $('.del').removeAttr('id');
    $(this).next('div').children('.del').attr('id', 'disqus_thread');

    var DIS_SHORT = 'allfreecourses',
          dsq = document.createElement('script');
    
    dsq.async = true;
    dsq.src = 'http://' + DIS_SHORT + '.disqus.com/embed.js';

    (document.head||document.body).appendChild(dsq); //Как head'a может не быть???!?
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question