How to join two jquery methods into one statement?

42 views Asked by At

I am using jquery to display bootstrap modal and want to add custom message at runtime. Here is what I am doing? but wondering if there is a way to merge two lines into one:-

$("#modalBody").append("saved successfully");
$("#modal").modal("show");

Bootstrap Modal:-

<div id="modal" class="modal fade" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <a href="#" class="close" data-dismiss="modal">&times;</a>
            </div>
            <div id="modalBody" class="modal-body">
                *adding custom message*
            </div>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
2

There are 2 answers

0
Gary Storey On BEST ANSWER

You could do it like this:

$("#modal").find("#modalBody").append("saved successfully").end().modal("show");

It's probably simple enough without combining them though.

0
John Wu On

Remove the newline character.

$("#modalBody").append("saved successfully"); $("#modal").modal("show");

Script engine will use the semicolon to determine where one statement ends and the next begins.

I hardly see the point, though.