-5

So I have an init function defined something like this:

init: function() {
$("#editRow").click(function() {
<code>
}
$(".removeRow").click(function() {
<code>
 }
}
  1. So, I was wondering if there was any way for me to call the class method removeRow in the onclick event itself? Essentially what I want to do is call the class method removeRow when my button gets clicked.

    var d = '<a href="javascript:void(0)" class="btn btn-xs btn-danger delete-new-row removeRow"><i class="material-icons md-18" title="Delete">delete</i></a>';
    

And whenever I click the button I get an error saying that removeRow() is not defined. So I am trying to figure out a way to call removeRow from pressing the button.

  1. If I wanted to call editRow in a different onclick event, would I do it the same way as removeRow or would that require a different approach?

Thanks for the help!

smarty_pants
  • 79
  • 1
  • 8

3 Answers3

-1

removeRow is not a function

you can use this instead:

$('.removeRow').click(function() {
  $( this ).remove();
)

For more reference: https://api.jquery.com/click/

In case you want to remove row on click of button:

$(<your-button-selector>).click(function() {
  $(<your-class-selector>).remove();
)
-1

you've forgot " in your jQuery. It need's to look like $(".removeRow").click(function() { <code> }, and you're trying to access .removeRow which means you're targeting a class, so you need to add var d = '<a> href="javascript:void(0)" class="removeRow"</a> and then you don't need the onClick function in your HTML because if you're targeting the button class, jQuery will do the onClick function.

Florian Dix
  • 3
  • 1
  • 4
-1

Let me see if I understood your question.

You want to call the code that's inside here?

$(".removeRow").click(function() {
<code>
 }

To achieve that result you can 'fake' a click on an element of that class using

$('.removeRow').click();
Antonio Neto
  • 176
  • 10