javascript - Get value of specific css class from selected tr -
I have an html table with several rows, all of which are equally structured.
The row I click through JQuery, but now I want to get the value of a certain field with the CSS class "book" that line the line within
$ (function () {$ (document) .on ('click', '.book_listing', function () {$ (this) .css ('background' , 'Red'); // is the code that I tried to get val console.log ($ (This) .find ('book'). Val ());})}}) & lt; Script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Table & gt; & Lt; Thead & gt; & Lt; TR & gt; & Lt; Th & gt; Stuff 1 & lt; / Th & gt; & Lt; Th & gt; Stuff 2 & lt; / Th & gt; & Lt; Th & gt; Stuff 3 & lt; / Th & gt; & Lt; / TR & gt; & Lt; / Thead & gt; & Lt; Tbody & gt; & Lt; Tr class = "book_listing" & gt; & Lt; Td> & Lt; Button class = "book" & gt; I want that value & lt; / Button & gt; & Lt; / Td> & Lt; Td> Other accessories & lt; / Td> & Lt; Td> And similarly & lt; / Td> & Lt; / TR & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; But I'm not the value of the button with the code above.
How can I use the value of the button from selected tr
The need to do
$ (this) .find ('book'). Text () or you can use
$ (this). ('.book'). Html () If you use .text (), you will get the text, if you use .html () then you will get text with markup Example < / P>
& lt; Button class = "book" & gt; Value I & lt; B & gt; Want & lt; / B & gt; & Lt; / Button & gt; .text () will come back: what I should value. HTML () will come back: value I & lt; B & gt; Want & lt; / B & gt; .val () I used for input, selection and text is the reason why it is not working on your code.
Comments
Post a Comment