I would like to change an attribute of a dynamic element with jQuery

Asked

Viewed 1,933 times

2

I have the following code that I thought would work, but nothing happens:

$(document).on('click', '#tab-departamentos a', function(){
  $('textarea').each(function(){
    var a = (this.scrollHeight-12)/20;

    //alert(a);

    $(this).attr('rows', a);
  })

  var href = $(this).attr('href');
  $(href).tab('show');
})

the link #tab-departamentos a serves to display the contents of a Tab do Bootstrap (thus: $(href).tab('show')).

But I can only edit the attribute rows of the main Tab, the others that are hidden and are dynamic elements are not changed.

  • 1

    Although you claimed the code is small, creating the fiddle would help the rest of people understand the full context of your problem.

1 answer

0

I tested it here and it seems to be working...

$(document.body).on('click', '#tab-departamentos a', function () {
        $('textarea').each(function () {
            var a = (this.scrollHeight - 12) / 20;
            alert(a);
            $(this).attr('rows', a);
        });

        var href = $(this).attr('href');
        //$(href).tab('show');
        alert(href);
    });

Or what exactly was the part that didn’t work? Presented some error in the console?

I just haven’t tested the panel, the rest is apparently working..

  • this link here (#tab-departments a) serves to show the contents of a Bootstrap Tab (http://getbootstrap.com/javascript/#tabs) like this ($(href).tab('show')), what happens is that I can only edit the Rows attribute of the main Tab, the others that are hidden and dynamic elements are not changed...

  • no error appears in the console, but only changes the active Panel understands?

  • I understand but I can’t fake the same situation here to try to help you....

  • Tá blz Rafael, vlw the attempt, I even tried to duplicate my function in the call back fade-in but it did not work...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.