开发者

Jquery how add an element to dom

开发者 https://www.devze.com 2023-04-07 15:45 出处:网络
Hello I have a function that add combobox into the page, and I need to use the values of these combobox. When I try to acces into the jquery code it don\'t work.

Hello I have a function that add combobox into the page, and I need to use the values of these combobox. When I try to acces into the jquery code it don't work. I think that I need to add the element to dom but I don't know how to do that. The id of combo is 's开发者_开发知识库electCombo'


You have several choices:

  • .prepend() http://api.jquery.com/prepend/
  • .append() http://api.jquery.com/append/
  • .insertAfter() http://api.jquery.com/insertAfter/
  • .insertBefore() http://api.jquery.com/insertBefore/


Try this way:

 $("<div/>", {

  // PROPERTIES HERE

  text: "Click me",

  id: "example",

  "class": "myDiv",      // ('class' is still better in quotes)

  css: {           
     color: "red",
     fontSize: "3em",
     cursor: "pointer"
  },

  on: {
    mouseenter: function() {
      console.log("PLEASE... "+ $(this).text());
    },
    click: function() {
      console.log("Hy! My ID is: "+ this.id);
    }
  },

  append: "<i>!!</i>",

  appendTo: "body"      // Finally, append to any selector

}); 
0

精彩评论

暂无评论...
验证码 换一张
取 消