Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JQuery/MVC simple question creating button click through JQuery

Posted on 2013-05-14
3
1,312 Views
Last Modified: 2013-05-15
Hello all,

I have a function that inserts a button after another button.  I need the class to call a click event of the button I am creating.  The class is using a button style.  This works on another area outside of the JQuery.  So here is what I have below.  The delete-button click event function is not getting into it the way I have this.   The onEdit function actually uses a Kendo editor template that places the delete button on the editor popup.  I think it may be based on the href not being correct.   Thanks all

  function onEditCollateral(e) {
        if (e.model.isNew()) {
            updateBtnText = $(".k-grid-update").html().replace("Update", "Create");
            $(".k-grid-update").html(updateBtnText);
            return;
        }
        
        $('<a class="delete-button k-button" href="\\\#"><span class="k-icon k-delete"></span>Delete</a>').insertAfter(".k-grid-update");
    }


    $(".delete-button").click(function(e) {
        e.preventDefault();
        alert('got this');
        var kendoWindow = $("<div />").kendoWindow({
            title: "Confirm",
            resizable: false,
            modal: true
        });

        kendoWindow.data("kendoWindow")
            .content($("#delete-confirmation").html())
            .center().open();

        kendoWindow
            .find(".delete-confirm,.delete-cancel")
            .click(function() {
                if ($(this).hasClass("delete-confirm")) {
                    $('<input />').attr('type', 'hidden')
                        .attr('name', 'cmdName')
                        .attr('value', 'Delete')
                        .appendTo('#LoanForm');

                    $("#LoanForm").submit();
                }

                kendoWindow.data("kendoWindow").close();
            })
            .end();
    });

Open in new window

0
Comment
Question by:sbornstein2
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 300 total points
ID: 39167648
When you bind an event using click() it will only bind the event to elements that exist when that function is called. If you then add another element dynamically, it won't have the same event binding. For this you need to use on() instead of click():

$(document).on("click", ".delete-button", function(e){
     ...
});

Open in new window

Read all about it here: http://api.jquery.com/on/
0
 

Author Comment

by:sbornstein2
ID: 39167861
this is perfect thank you.   Do you know how I can call an action method in a controller passing a parameter I have in my model.  The param is model.loanid
0
 

Author Closing Comment

by:sbornstein2
ID: 39168973
thanks
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question