JQuery replace element text

Hi I am trying to replace a div in a jQuery dropdown. The value to be replaced is the "title" of the pop-up window that says "Choose an alternative:" when nothing is selected. Then, when the user selects an alternative from the drop-down list, this alternative is highlighted and also replaces “Choose Alternative” so that the user can see what they have selected by closing the drop-down list.

How should I do it? HTML:

    <div class="step_content">
        <div class="vertical_text">Choose alternative</div>
        <div class="vertical_content dropdown_fade">
            <div class="menu_corner top_left_vertical"></div>
            <div class="menu_corner top_right_vertical"></div>                                                                      
            <div class="button_slide" rel="slide1">Pick alternative:</div>
            <div class="content_slide slide1">
                <input id="Button19" class="button_vertical damage_button" type="button" value="Alternative 1" size="10px" />
                <input id="Button20" class="button_vertical damage_button" type="button" value="Alternative 2" />  

            </div>                                            
            <div class="menu_corner bottom_left_vertical"></div>
            <div class="menu_corner bottom_right_vertical"></div>                   
        </div>                
    </div>             

I have the following javaScript lines. I am not sure how to continue to do this.

$(function () {
        $('.damage_button').click(function () {
            $('.button_slide').replaceWith("<div class='some_class' >" + $(this) + "</div>");
        });
});

I get it to replace what I want to replace, but it just shows "[Object of object]". Thanks for reading!

* bold * Edit: -, , , ? , !

+3
2
$(function () {
        $('.damage_button').click(function () {
            $('.button_slide').replaceWith("<div class='some_class' >" + $(this).val() + "</div>");
        });
});

val() INPUT ( - INPUT) html() text() INPUT.

, [Object object], , $(this) , jQuery toString(), , . , val().

+1

.val(), <input> , :

$(function () {
  $('.damage_button').click(function () {
    $('.button_slide').replaceWith("<div class='some_class' >" + $(this).val() + "</div>");
  });
});

this <input>, , $(this) jQuery. .toString() [Object object], .val(), .

+1

Source: https://habr.com/ru/post/1773869/


All Articles