link2877 link2878 link2879 link2880 link2881 link2882 link2883 link2884 link2885 link2886 link2887 link2888 link2889 link2890 link2891 link2892 link2893 link2894 link2895 link2896 link2897 link2898 link2899 link2900 link2901 link2902 link2903 link2904 link2905 link2906 link2907 link2908 link2909 link2910 link2911 link2912 link2913 link2914 link2915 link2916 link2917 link2918 link2919 link2920 link2921 link2922 link2923 link2924 link2925 link2926 link2927 link2928 link2929 link2930 link2931 link2932 link2933 link2934 link2935 link2936 link2937 link2938 link2939 link2940 link2941 link2942 link2943 link2944 link2945 link2946 link2947 link2948 link2949 link2950 link2951 link2952 link2953 link2954 link2955 link2956 link2957 link2958 link2959 link2960 link2961 link2962 link2963 link2964 link2965 link2966 link2967 link2968 link2969 link2970 link2971 link2972 link2973 link2974 link2975 link2976 link2977 link2978 link2979 link2980 link2981 link2982 link2983 link2984 link2985 link2986 link2987 link2988 link2989 link2990 link2991 link2992 link2993 link2994 link2995 link2996 link2997 link2998 link2999 link3000 link3001 link3002 link3003 link3004 link3005 link3006 link3007 link3008 link3009 link3010 link3011 link3012 link3013

[Vue.js] Add active class a column to table (as in netflix)

I need help to select a table header and select the column using classes. As in Netflix. I’m noob in VueJS

Example GIF

My code is

<table class=”table”>
<thead class=”text-center”>
<th scope=”col”><button type=”button” class=”btn plan_columnA selected” @click=”planSelect(‘plan_columnA’)”>Column A</button></th>
<th scope=”col”><button type=”button” class=”btn plan_columnB” @click=”planSelect(‘plan_columnB’)”>Column B</button></th>
<th scope=”col”><button type=”button” class=”btn plan_columnC” @click=”planSelect(‘plan_columnC’)”>Column C</button></th>

<tbody class=”text-center”>
<td class=”plan_columnA selected”>Mark</td>
<td class=”plan_columnB”>Otto</td>
<td class=”plan_columnC”>@mdo</td>
<td class=”plan_columnA selected”>Jacob</td>
<td class=”plan_columnB”>Thornton</td>
<td class=”plan_columnC”>@fat</td>
<td class=”plan_columnA selected”>Larry</td>
<td class=”plan_columnB”>the Bird</td>
<td class=”plan_columnC”>@twitter</td>

My style is

.btn {
background-color: darkgrey;
color: white;
button.selected {
background-color: red;
td.selected {
color: red;

I try to do this, but I do not know if it’s right

export default {
data () {
return {
planSelected: ‘’,

methods: {
planSelect (plan) {
this.planSelected = plan;

$(‘.’ + this.planSelected).addClass(‘selected’);

I tried JQuery, but to do it in VueJS.


Solution :

That’s fairly easy, i’ve made an example for you in a fiddle, hope it helps you on the way. It should be made more dynamically, for better overview, but you can play around with the code i’ve made.

In the perfect scenario, you would generate all rows/columns from a data variable, instead of doing all this manually.

What i’ve made is just having 1 data variable, which you set and check for on the different tds and buttons.

data: () => ({
planSelected: ‘plan_columnA’

Button to choose the plan:

<button type=”button” class=”btn plan_columnA” :class=”{selected: planSelected === ‘plan_columnA’ }” @click=”planSelected = ‘plan_columnA’”>Column A</button>

And the actual column to show selected

<td class=”plan_columnA” :class=”{selected: planSelected === ‘plan_columnA’ }”>Mark</td>

Pro tip: Never combine jQuery and VueJS - Just use VueJS