0

I am still new to JQuery but what I am trying to do is this:

  1. Click my edit button and call someFunction()

  2. Jquery then will hide my edit button, show my save button, and hide the delete button.

  3. Get the item.ID and save as a var for later.

Here is my attemp thus far.

The button set:

<td class="col-lg-3 col-lg-offset-1">
         <span style="visibility:hidden">@Html.DisplayFor(modelItem => item.ID)</span>

         <span class="item-edit-button">
         <button type="button" onclick="someFunction()" class=" btn btn-warning col-lg-4"><span style="margin-right: 5px" class="glyphicon glyphicon-pencil"></span>Edit</button>
         </span>

         <span class="item-save-button">
         <button type="button" class="btn btn-success col-lg-4"><span style="margin-right: 5px" class="glyphicon glyphicon-trash"></span>Save</button>
         </span>

         <span class="item-delete-button">
         <button type="button" class="btn btn-danger col-lg-4" onclick="location.href='@Url.Action("Delete", "Movie", new { id = item.ID })' ;return false;"><span style="margin-right: 5px" class="glyphicon glyphicon-trash"></span>Delete</button>
         </span>
</td>

my JQuery attempt (without getting the var since I haven't gotten to that point yet)

<script>
    function someFunction() {
          someFunction //trying to get current item/value/button/ect..
                .hide()
                .next("span.item-save-button")
                .show()
                .next("span.item-delete-button")
                .hide()
    };
</script>

EDIT: How to do this using the answer below

function someFunction(element) {
        $(element).hide();
        $(element).closest("td").find("span.item-save-button").show();
        $(element).closest("td").find("span.item-delete-button").hide();
    }

1 Answer 1

3

you need to pass element reference like this:

<button type="button" onclick="someFunction(this)">Click ME</button>

and in function:

function someFunction(element) {

                $(element).hide();
                $(element).closest("td").find("span.item-save-button").show();
                $(element).show();
                $(element).closest("td").find("span.item-delete-button").hide();
                $(element).hide();
    }
Sign up to request clarification or add additional context in comments.

11 Comments

ah nice! However I must have named things wrong. It hides the Edit button, but does not show the Save and does not hide the Delete
Hmmm doing the same thing still
i mistakenly removed hide() while editing..:P so thats why it not worked
Well now it hides Edit, Shows Saves, but Delete is still visible hahaha
why don't you just add some more classes to save and delete like "editMode" and then just do $(element).('.editMode').show()
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.