Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get text value of calling <button> in jQuery?

Tags:

jquery

button

I tried following code but no work:

 <button type="button" class="btn btn-info filter-new" id="btn_Filter_New">New</button>
 $("btn_Filter_New").click(function ()
 {
      var ButtonText = $(this).val();
 }
like image 579
SE_VS_NET Avatar asked Jan 22 '14 20:01

SE_VS_NET


People also ask

How to get value of text input in jQuery?

jQuery val() method is used to get the value of an element. This function is used to set or return the value. Return value gives the value attribute of the first element.

How do you access text of a button?

String buttonText = button. getText(); I can get the id from a pressed button: int buttinID = view.

How Get button data attribute value in jQuery?

How Get button data attribute value in jQuery? Answer: Use the jQuery attr() Method You can simply use the jQuery attr() method to find the data-id attribute of an HTML element.

How to get text of an element jQuery?

Answer: Use the jQuery text() method You can simply use the jQuery text() method to get all the text content inside an element. The text() method also return the text content of child elements.


1 Answers

Use the .text() function. Also use the id selector correctly #btn_Filter_New.

 $("#btn_Filter_New").click(function () {
      var ButtonText = $(this).text();
 });
like image 116
dcodesmith Avatar answered Oct 01 '22 02:10

dcodesmith