table - Multi-select and deselect of columns - jquery -
i want write content of 1 or more columns array. should possible deselect column. use following code address column, don't know how content.
$("td").click(function () { var columnno = $(this).index(); $(this).closest("table") .find("tr td:nth-child(" + (columnno + 1) + ")") .css("color", "red"); });
any appreciated
thank you!
try this:
$(document).ready(function(){ var text = []; $("td").click(function () { var columnno = $(this).index(); $(this).closest("table") .find("tr td:nth-child(" + (columnno + 1) + ")") .toggleclass("selected"); var val = $(this).closest("table") .find("tr td:nth-child(" + (columnno + 1) + ")").text(); // column text if($(this).hasclass( "selected" )){ //to check whether user selected or not if($.inarray(val,text)<0){ //check value exists in array text.push(val); } }else{ text.splice($.inarray(val, text),1); //if user deselect remove column text array } console.log(text); }); });
Comments
Post a Comment