Click event is not working for dynamically added button

I reffered Creating a div element in jQuery and creatd a div element using javascript. However when I added a button element dynamically, click is not working. What change do we need to do to make the button click working? Note: We cannot move the function outside of document.ready due to kendo control requirements mentioned in Binding to multiple view models nested in the Dom Updated Refer

Click事件不适用于动态添加的按钮

我反对在jQuery中创建div元素并使用javascript创建div元素。 但是,当我动态添加一个按钮元素时,单击不起作用。 我们需要做些什么才能使按钮点击工作? 注意:由于绑定到嵌套在Dom中的多个视图模型中提到的kendo控件需求,我们无法将该功能移到document.ready之外 更新的参考 使用jQuery on()连接点击事件不会通过Ajax调用触发注入的HTML 如何为新注入的html添加jquery事件处理程序? 在通过jquery注入html之后,

how to print entire HTML element in JavaScript?

I want to print the entire element including tag name, attribute name/value pairs and innerHTML. How can I do it in JavaScript (jQuery)? for example: var elArr = document.getElementsByTagName('link'); alert(elArr[0].printEntireElement()); //expected output might be <link href="/css/common.css" rel="stylesheet" type="text/css">` Note that for link element outerHTML is not defined! 使

如何在JavaScript中打印整个HTML元素?

我想打印整个元素,包括标签名称,属性名称/值对和innerHTML。 我怎样才能在JavaScript(jQuery)中做到这一点? 例如: var elArr = document.getElementsByTagName('link'); alert(elArr[0].printEntireElement()); //expected output might be <link href="/css/common.css" rel="stylesheet" type="text/css">` 请注意,对于链接元素,不定义outerHTML! 使用一个像这样的外部HTMLHTML插件,或者这个插件。 如

dynamically creating div using javascript/jquery

I have two div called "answerdiv 1" & "answerdiv 2" in html. now i want to give/create div id uniquely like "answerdiv 3" "answerdiv 4" "answerdiv 5" and so on. Using javascript/jquery how can i append stuff in these dynamically created divs which id should be unique? in my project user can add "n" numbers of div, there is no s

使用javascript / jquery动态创建div

我有两个div在html中称为“answerdiv 1”和“answerdiv 2”。 现在我想给/创建div id唯一像“answerdiv 3”“answerdiv 4”“answerdiv 5”等。 使用javascript / jquery我该如何在这些动态创建的div中添加这些id应该是唯一的东西? 在我的项目中用户可以添加“n”个div的数量,没有严格的限制。 帮帮我。 感谢Adv ================================================== ============================== 我的HTML代码是: <d

Javascript creating <div> on the fly

I have aa link that looks similar to this <a href="/home/category/blog/1" id="blog">Blog</a> As you can the link has an ID of 'blog' what I want to do is to create an div on the fly with the ID from the link that was clicked so if the 'blog' is clicked, then the markup would be <div id="blog"> <!--some content here--> </div> Like wise if for insta

动态创建<div>的JavaScript

我有一个类似这样的链接 <a href="/home/category/blog/1" id="blog">Blog</a> 正如你可以链接有一个ID为'博客'我想要做的就是创建一个动态div与点击链接的ID,所以如果点击'博客',那么标记将是 <div id="blog"> <!--some content here--> </div> 就像明智的如果新闻链接被点击,然后我想, <div id="news"> <!--some content here--> </div> 如果可能

What is the most efficient way to create HTML elements using jQuery?

Recently I've been doing a lot of modal window pop-ups and what not, for which I used jQuery. The method that I used to create the new elements on the page has overwhelmingly been along the lines of: $("<div></div>"); However, I'm getting the feeling that this isn't the best or the most efficient method of doing this. What is the best way to create elements in jQuery f

什么是使用jQuery创建HTML元素的最有效方法?

最近我一直在做很多模式窗口弹出窗口,而不是,我使用jQuery。 我用来在页面上创建新元素的方法绝大多数都是这样的: $("<div></div>"); 但是,我感觉这不是最好的或最有效的方法。 从性能的角度来看,在jQuery中创建元素的最佳方式是什么? 这个答案有以下建议的基准。 我使用$(document.createElement('div')); 基准测试显示这种技术是最快的。 我推测这是因为jQuery不必将其标识为元素并自己创

jquery or JS create child element and assign an ID

This question already has an answer here: Creating a div element in jQuery [duplicate] 26 answers Try this $("#fDistList").append('<option id="'+ item.ID + '">' + item.GROUP_NAME + '</option>'); When you do $("option").attr('id', item.ID); you are reselecting all option elements and setting their ID attribute. 你可以像这样做,一次通过$('<option/>',{ text: item.G

jquery或JS创建子元素并分配一个ID

这个问题在这里已经有了答案: 在jQuery中创建div元素[复制] 26个答案 尝试这个 $("#fDistList").append('<option id="'+ item.ID + '">' + item.GROUP_NAME + '</option>'); 当你这样做 $("option").attr('id', item.ID); 您正在重新选择所有option元素并设置其ID属性。 你可以像这样做,一次通过$('<option/>',{ text: item.GROUP_NAME, id:item.ID }).appendTo('#fDistList')

Javascript: How to detect if browser window is scrolled to bottom?

I need to detect if a user is scrolled to the bottom of a page. If they are at the bottom of the page, when I add new content to the bottom, I will automatically scroll them to the new bottom. If they are not at the bottom, they are reading previous content higher on the page, so I don't want to auto-scroll them since they want to stay where they are. How can I detect if a user is scrolle

Javascript:如何检测浏览器窗口是否滚动到底部?

我需要检测用户是否滚动到页面的底部。 如果他们在页面的底部,当我向底部添加新内容时,我会自动将它们滚动到新的底部。 如果他们不在底部,他们正在读取页面上更高的内容,所以我不想自动滚动他们,因为他们想保持他们在哪里。 如何检测用户是滚动到页面底部还是滚动页面上方? window.onscroll = function(ev) { if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { // you're a

jQuery : on horizontal scroll tell which element is in viewport

This question already has an answer here: Check if element is visible after scrolling 38 answers 假设#stickers拥有正确的CSS来进行溢出滚动(如果没有,您的滚动处理程序将永远不会触发。) var scrollingIsThrottled = false; var sticker = $(".sticker"); $("#stickers").scroll(function() { var stickers_width = $(this).width(); if (!scrollingIsThrottled) { scrollingIsThrottled = true; var S

jQuery:在水平滚动上告诉哪个元素在视口中

这个问题在这里已经有了答案: 滚动38个答案后,检查元素是否可见 假设#stickers拥有正确的CSS来进行溢出滚动(如果没有,您的滚动处理程序将永远不会触发。) var scrollingIsThrottled = false; var sticker = $(".sticker"); $("#stickers").scroll(function() { var stickers_width = $(this).width(); if (!scrollingIsThrottled) { scrollingIsThrottled = true; var StickerMatchingExpression = sticker.

Scroll top after popping up a new window.

This question already has an answer here: Check if element is visible after scrolling 38 answers Because You open a new window, js is loaded second time and click event wasn't executed. You can use something like: $(document).ready(function () { if (window.location.href.indexOf("my_url") > -1) { $('html,body').animate({ scrollTop: "0px" }); // or 150px } }); or use so

弹出一个新窗口后滚动顶部。

这个问题在这里已经有了答案: 滚动38个答案后,检查元素是否可见 由于您打开了一个新窗口,第二次加载js并且未执行单击事件。 你可以使用像这样的东西: $(document).ready(function () { if (window.location.href.indexOf("my_url") > -1) { $('html,body').animate({ scrollTop: "0px" }); // or 150px } }); 或者为setTimeout使用一些全局变量,并在执行后将其分解。 你的代码在父窗口中运行,

How to tell if something is scrolled into view?

This question already has an answer here: Check if element is visible after scrolling 38 answers As has been posted multiple times here: http://imakewebthings.com/jquery-waypoints/ does exactly what you are looking for. Are you trying to get something like this Edited DEMO Script: $(function(){ var a;var c=false; var b=$("#popContent"); var e=$(window);

如何判断是否有东西滚动到视图中?

这个问题在这里已经有了答案: 滚动38个答案后,检查元素是否可见 正如在这里发布多次: http://imakewebthings.com/jquery-waypoints/ 正是你正在寻找的东西。 你是否想要得到这样的东西? 编辑DEMO 脚本: $(function(){ var a;var c=false; var b=$("#popContent"); var e=$(window); var d=$('#footer').position().top; e.scroll(function(){ window.cl