gamer
gamer

Reputation: 5863

jQuery DOM inside form is not updating in for loop

I have a django template with the form:

{% for user in users %}
    <form class="myform">
        <div class="title"></div>
        Some form element

    </form}
{% endfor %}

I'm getting the form in jQuery like:

var infoForm = $(this).next('myform');

to update the title class, i do this:

infoForm.find('title').html('<div class='my-title'>My title</div>');

But it doesn't update the DOM,

What am i doing wrong ?

Upvotes: 0

Views: 103

Answers (3)

Syed Ekram Uddin
Syed Ekram Uddin

Reputation: 3091

$('.myform').first().find('.title').text('My Title');

or

$('.myform').get(0).find('.title').text('My Title');

Upvotes: 0

Gabriel
Gabriel

Reputation: 265

Use

('.myform');

instead of

('myform');

and

('.title')

instead of

('title')

See Class Selector (“.class”)

Upvotes: 2

Amresh Venugopal
Amresh Venugopal

Reputation: 9549

Instead of

infoForm.find('title').html('<div class='my-title'>My title</div>');

Does this work?

$('.title').addClass('my-title').removeClass('title');

Upvotes: 0

Related Questions