Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7523241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:44:24+00:00 2026-05-30T02:44:24+00:00

I am new to jQuery and I am using jQuery 1.7.1 to learn Knockout

  • 0

I am new to jQuery and I am using jQuery 1.7.1 to learn Knockout JS, I was following a video demo by the author. In his example he has a tag something like

<a href="#" class="button-delete">Delete</a>

and in the viewmodel he has something like

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

When I tried in my side when I click on the delete button I never see the console.log show up on the console window of the Chrome F12 screen. I have two part question here

  1. Is there something I am doing wrong which is preventing the console message to show up?
  2. If I do not have a class to do css, is there any other way to perform the same task in the viewmodel?

edit:
I corrected my typo, the code has proper parenthesis (I use web matrix so it take care of those issues). Here is my html

<!DOCTYPE html>
<script src="Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="Scripts/knockout-2.0.0.js" type="text/javascript"></script>
<script src="Scripts/ViewModel.js" type="text/javascript"></script>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
</head>
<body onload="init()">
    <input data-bind="value: tagsToAdd"/>
    <button data-bind="click: addTag">Add</button>
   <ul data-bind="foreach: tags">
           <li>
               <span data-bind="text: Name"></span>
               <div>
                   <a href="#" class="btn btn-danger" >Delete</a>
               </div>
           </li>
   </ul>
</body>
</html>

Here is my knockout viewmodel

/// <reference file="jquery-1.7.1.js" />
/// <reference file="knockout-2.0.0.js" />

var data = [
   {Id: 1, Name: "Ball Handling" },
   {Id: 2, Name: "Shooting" },
   {Id: 3, Name: "Rebounding" }
];

function viewModel()
{
    var self = this;    
    self.tags = ko.observableArray(data);
     self.tagsToAdd = ko.observable("");

    self.addTag = function() {
       self.tags.push({ Name: this.tagsToAdd() });
       self.tagsToAdd("");
    }
}


$(document).on("click", ".btn-danger", function () {
    console.log("inside");
    });


 var viewModelInstance;
function init(){
    this.viewModelInstance = new viewModel();
    ko.applyBindings(viewModelInstance);    
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:44:25+00:00Added an answer on May 30, 2026 at 2:44 am

    Looks like you got your first answer already. On the “other ways” to bind the click event if you don;t have a class name, there are a few options. You could add an id to the tag, and call it that way. Or if you don’t want to add a class nor an id, you can use the data-bind syntax with the “click” built-in binding to invoke a method on your view model (obviously this is not the jquery evnet style, so its up to you how you want to wire up your events). Like this:

    <button data-bind="click: someMethod">Click me</button>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to using jquery and would like to know how to append
I am relatively new to using jQuery and would like to use the load
I'm using jQuery to change the HTML of a tag, and the new HTML
I'm very new to jQuery but keen to learn. Because of this I'm using
Using jQuery UI 1.8rc3 combined with the new jquery.effects.fade.js code, I've been able to
I am trying to open a few links in a new window using Jquery
I'm using jQuery to dynamically add new divs containing a few fields. I'm adding
I am new to jQuery and cannot get a selector to work using the
I am using jQuery, and wish to make certain links open in a new
I'm using JQuery to switch out an image src thusly: $(#myImg).attr(src, ../../new.gif); notice the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.