How do I change the HTML content of a dynamically generated element in Jquery

not_a_generic_user

I long ago learned that for dynamically added content, attaching listeners and events like click and focus must be done by using $(document).on('click','[ID]', function(){});.... etc.

However, what I'm trying to do is change the HTML value of a specific element that has been dynamically added.

For instance, I use this code to add the element:

$('.friend_chooser_pop').html("<div id='#friend_chooser_list'></div>"); 

Now how do I access #friend_chooser_list and set its HTML value? Neither one of these works:

$('#friend_chooser_list').html('something');
document.getElementById('friend_chooser_list').innerHTML = 'something';
Allan Kimmer Jensen

This should work, your problem is that you included a # in your id, this is not needed here.

This would work.

$('.friend_chooser_pop').html("<div id='friend_chooser_list'></div>");
$('#friend_chooser_list').html('something');

If this is your intend to include # in the ID and you want it to work you can use it like this:

$("#\\#friend_chooser_list").html('something');

It's escaping the # and allowing jQuery to get the right element anyway. I would not recommend this, it can get confusing pretty fast.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How to get the html content of a clicked element using jQuery

来自分类Dev

Insert an encoded character as text in a dynamically generated element using jquery

来自分类Dev

How to work with string.format for nth parameter dynamically generated jquery

来自分类Dev

How do I change my Content-Transfer-Encoding header in Python?

来自分类Dev

How to set dynamic input name which generated dynamically using jquery live()

来自分类Dev

How do I give a list dynamically without hardcoding to MongoDB's $in?

来自分类Dev

How do I dynamically reload a module in a custom package?

来自分类Dev

How do I override the response content in a JMeter WebDriver sampler test?

来自分类Dev

How do I include jquery in javafx webview?

来自分类Dev

How do I change the boot menu when I have no display?

来自分类Dev

How can I create an element in HTML/CSS with a semicircle border at the top?

来自分类Dev

Jquery html() and reserved element names

来自分类Dev

How to include a html string dynamically

来自分类Dev

Dynamically appending HTML elements using jQuery not working

来自分类Dev

How do I change the browser accept-language

来自分类Dev

How do i change the location directory of python open document?

来自分类Dev

How do I change the property of one type of Child Controls in a form?

来自分类Dev

How do I change ImmutableSet from guava collections?

来自分类Dev

How do i change from mouse to touch instead?

来自分类Dev

How do I dynamically inject an Angular2 sub component via typescript code?

来自分类Dev

How do I get my nested if statement to work in jQuery

来自分类Dev

How do I access a jQuery plugin variable from within method?

来自分类Dev

How do I check for column content in a typo3 fluid template?

来自分类Dev

In Plone, how do I fix Archetypes content that is missing the cmf_uid() annotation?

来自分类Dev

How to dynamically insert the list data into an html table

来自分类Dev

How can I change the selected text when using Multiple Select jQuery plugin

来自分类Dev

How to use jquery content with Vanilla js

来自分类Dev

How do I change this snippet to enable delegation on a form's ajax events?

来自分类Dev

How To Do A Page Break in a PDF Generated Using Pechkin

Related 相关文章

  1. 1

    How to get the html content of a clicked element using jQuery

  2. 2

    Insert an encoded character as text in a dynamically generated element using jquery

  3. 3

    How to work with string.format for nth parameter dynamically generated jquery

  4. 4

    How do I change my Content-Transfer-Encoding header in Python?

  5. 5

    How to set dynamic input name which generated dynamically using jquery live()

  6. 6

    How do I give a list dynamically without hardcoding to MongoDB's $in?

  7. 7

    How do I dynamically reload a module in a custom package?

  8. 8

    How do I override the response content in a JMeter WebDriver sampler test?

  9. 9

    How do I include jquery in javafx webview?

  10. 10

    How do I change the boot menu when I have no display?

  11. 11

    How can I create an element in HTML/CSS with a semicircle border at the top?

  12. 12

    Jquery html() and reserved element names

  13. 13

    How to include a html string dynamically

  14. 14

    Dynamically appending HTML elements using jQuery not working

  15. 15

    How do I change the browser accept-language

  16. 16

    How do i change the location directory of python open document?

  17. 17

    How do I change the property of one type of Child Controls in a form?

  18. 18

    How do I change ImmutableSet from guava collections?

  19. 19

    How do i change from mouse to touch instead?

  20. 20

    How do I dynamically inject an Angular2 sub component via typescript code?

  21. 21

    How do I get my nested if statement to work in jQuery

  22. 22

    How do I access a jQuery plugin variable from within method?

  23. 23

    How do I check for column content in a typo3 fluid template?

  24. 24

    In Plone, how do I fix Archetypes content that is missing the cmf_uid() annotation?

  25. 25

    How to dynamically insert the list data into an html table

  26. 26

    How can I change the selected text when using Multiple Select jQuery plugin

  27. 27

    How to use jquery content with Vanilla js

  28. 28

    How do I change this snippet to enable delegation on a form's ajax events?

  29. 29

    How To Do A Page Break in a PDF Generated Using Pechkin

热门标签

归档