1

I'm trying to unbold text of a row on button click just like gmail messages. For that i'm using jquery to perform that action. On a particular row, when the button is clicked the text of that row would get unbold and the button would be disabled.

Below is what I've done.

.cshtml

<table class="table table-bordered table-responsive table-hover" style="font-weight: 700;">
        @for (int i = 0; i<ViewBag.notifications.Count;i+=2)
        {
            <tr>
                <td>
                    @ViewBag.notifications[i]
                </td>

                <td>
                    @ViewBag.notifications[i + 1]
                </td>

                <td>
                    <input type="button" class="readmessages" value="asdasd" data-toggle="toggle" />
                </td>

            </tr>
        }   
        </table>

<script>
$(".readmessages").click(function () {
            var $row = $(this).parents('tr');
            var text = $row.find('td:nth-child(2)').text();

        });
</script>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Salar Muhammad
  • 334
  • 1
  • 8
  • 21
  • Since you tagged this JavaScript, please RENDER the HTML and post a [mcve] using the `<>` snippet editor. @Adelin There seems NO need for the other tags since it is not related to the backend – mplungjan Jan 26 '18 at 06:54
  • @mplungjan ok but perhaps while rendering OP can add in the backend some useful code so that JS can handle this task easily, which is why I thought it's relevant to know the backend used – Adelin Jan 26 '18 at 06:57
  • I do not see that at all. The solution is `$(this).parents('tr td:nth-child(2)').find("b").contents().unwrap(); $(this).prop("disabled",true);` – mplungjan Jan 26 '18 at 06:59
  • .find("b"), what does this mean? – Salar Muhammad Jan 26 '18 at 07:07
  • Your posted solution doesn't work – Salar Muhammad Jan 26 '18 at 07:15

0 Answers0