Change the HTML of an Expanding Row - html

I am looking to have a + change to a - when my table row expands. I have provided my code below and also through JS Fiddle here: https://jsfiddle.net/k37f0cbp/2/
$(document).ready(function() {
$('tr.parent')
.css("cursor", "pointer")
.attr("title", "click")
.click(function() {
$(this).siblings('.child-' + this.id).toggle();
});
$('tr[#class^=child-]').children('td').hide();
});
$if(('tr[#class^=child-]').is(":visible")).click(function() {
$('.plus', this).html('-');
});
th,
td {
border-bottom: 1px solid black;
}
th,
td {
padding: 15px;
}
tr:hover {
background-color: #f5f5f5;
}
[class*='child-row'] {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table style="width:100%">
<tbody>
<tr class="parent" id="row1" title="click">
<td><span class="plus">+</span></td>
<td>Paper Idea One</td>
</tr>
<tr class="child-row1">
<td>testing</td>
</tr>
</tbody>
</table>

$(document).ready(function ()
{
//add a flag
var expanded = false;
$('tr.parent')
.css("cursor", "pointer")
.attr("title", "click")
.click(function ()
{
$(this).siblings('.child-' + this.id).toggle();
//check flag, update value of a button and update a flag
if(expanded)
{
$(".plus").text("+");
expanded = false;
}
else
{
$(".plus").text("-");
expanded = true;
}
});
$('tr[#class^=child-]').children('td').hide();
});
$if (('tr[#class^=child-]').is(":visible")).click(function()
{
$('.plus', this).html('-');
});

After many more hours exploring this, I combined what the contributor above added with some other things I experimented with and came up with a more elegant and accurate answer that accounts for multiple rows. The only trick here is adding an id to the plus element that is equivalent to the parents id.
$(document).ready(function ()
$('tr.parent')
.css("cursor", "pointer")
.attr("title", "click")
.click(function ()
{
$(this).siblings('.child-' + this.id).toggle();
var s = this.id;
if ($(this).next().is(":visible")) {
$('#' + s + '.plus').html('-');
}
if ($(this).next().is(":hidden")) {
$('#' + s + '.plus').html('+');
}
})
)};

Related

HTML hidden not submitting

I have been developing a personal project for a couple of weeks now, and over the past week something changed and the HTML Hidden helper function stopped submitting for some reason and I can't find out why.
Here is the view.
#model GolfTracker.ViewModels.NewRoundViewModel
#{
ViewBag.Title = "NewRound";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>New Round</h2>
#using (Html.BeginForm("Finish", "Rounds"))
{
<div class="form-group">
<p>Select course:</p>
#Html.DropDownListFor(m => m.Round.Course, new SelectList(Model.Courses), "Select course", new { #class = "form-control", #id = "courseDropdown" })
</div>
<table class="table-dark" id="scorecard" style="text-align: center; border: 2px solid #00bc8c; table-layout: fixed">
<thead class="table-secondary">
<th style="vertical-align: middle; padding: 0px; border: 0px">
#
</th>
#for (int i = 1; i < 19; i++)
{
<th style="padding-left: 0px; padding-right: 0px; vertical-align: middle; padding: 0px; border: 0px" width="4.5%">
<div>
#i
</div>
</th>
}
<th style="padding: 0px; border: 0px">
Total
</th>
</thead>
<tr class="table-secondary">
<td style="vertical-align: middle">
Par
</td>
#for (int i = 1; i < 19; i++)
{
<td style="padding-left: 0px; padding-right: 0px; vertical-align: middle">
<div id="hole-#i-par">
</div>
</td>
}
<td>
<div id="par-sum">
</div>
</td>
</tr>
<tr class="table-secondary">
<td style="vertical-align: middle">
Yardage
</td>
#for (int i = 1; i < 19; i++)
{
<td style="padding-left: 0px; padding-right: 0px;">
<div id="hole-#i-yardage">
</div>
</td>
}
<td id="yard-sum"></td>
</tr>
<tr id="scores-array" class="table-secondary">
<td style="vertical-align: middle">
Score
</td>
#for (int i = 1; i < 19; i++)
{
Model.Round.Scores.Add(new GolfTracker.Models.HoleScore()
{
Score = 0
});
<td style="padding-left: 0px; padding-right: 0px;" align="center">
#Html.TextBoxFor(m => m.Round.Scores[i - 1].Score, new { #class = "form-control", #id = "tb-h" + i, #style = "padding-left: 0px; padding-right: 0px; text-align: center; display: block" })
</td>
}
<td id="score-sum"></td>
</tr>
<tr id="putts-array" class="table-secondary">
<td style="vertical-align: middle">
Putts
</td>
#for (int i = 1; i < 19; i++)
{
<td style="padding-left: 0px; padding-right: 0px;" align="center">
#Html.TextBoxFor(m => m.Round.Scores[i - 1].Putts, new { #class = "form-control", #id = "tb-p" + i, #style = "padding-left: 0px; padding-right: 0px; text-align: center; display: block" })
</td>
}
<td id="putts-sum"></td>
</tr>
<tr id="uad-array" class="table-secondary">
<td style="vertical-align: middle">
Up-and-Down
</td>
#for (int i = 1; i < 19; i++)
{
<td style="padding-left: 0px; padding-right: 0px; text-align: center; vertical-align: middle;">
#Html.CheckBoxFor(m => m.Round.Scores[i - 1].UAD, new { #class = "form-check-input", #id = "chb-uad" + i, #style = "margin: 0px; position: relative; width: 20px; height: 20px;" })
</td>
}
<td id="uad-sum"></td>
</tr>
<tr id="ss-array" class="table-secondary">
<td style="vertical-align: middle">
Sand Save
</td>
#for (int i = 1; i < 19; i++)
{
<td style="padding-left: 0px; padding-right: 0px; text-align: center; vertical-align: middle;">
#Html.CheckBoxFor(m => m.Round.Scores[i - 1].SS, new { #class = "form-check-input", #id = "chb-ss" + i, #style = "margin: 0px; position: relative; width: 20px; height: 20px;" })
</td>
}
<td id="ss-sum"></td>
</tr>
</table>
<div class="form-group">
#Html.LabelFor(m => m.Round.Date)
#Html.TextBoxFor(m => m.Round.Date, "{0:d MMM yyyy}", new { #class = "form-control", Type = "date" })
</div>
#Html.Hidden("numHoles", Model.Round.Holes)
#Html.Hidden("score", Model.Round.Score)
#Html.Hidden("putts", Model.Round.Putts)
#Html.Hidden("uad", Model.Round.UAD)
#Html.Hidden("ss", Model.Round.SS)
<div class="form-group">
#Html.LabelFor(m => m.Round.Fairways)
#Html.TextBoxFor(m => m.Round.Fairways, new { #class = "form-control" })
</div>
<div class="form-group">
#Html.LabelFor(m => m.Round.GIR)
#Html.TextBoxFor(m => m.Round.GIR, new { #class = "form-control" })
</div>
<button type="submit" class="btn btn-primary" id="save">Save</button>
}
Here are the scripts. By the time the user presses the save button, all the data is already calculated and saved to their respective elements. The hidden inputs do indeed have the data, but they don't send it back to the model on submit.
Edit: I am aware there are multiple repeated scripts that could be created through using a loop, but I tried that and it didn't work because each iteration kept using the final index rather than the correct one. I had to resort to declaring them manually.
#section scripts
{
<script>
$(document).ready(function () {
$("#courseDropdown").change(function () {
$.ajax({
type: "GET",
url: "/api/coursesapi/" + $(this).val(),
contentType: "application/json",
success: function (course) {
$("#scorecard").show();
if (course != null) {
var yardSum = 0;
var holeYardage;
var holePar;
for (var i = 1; i < 19; i++) {
holeYardage = document.getElementById("hole-" + i + "-yardage");
holePar = document.getElementById("hole-" + i + "-par");
holeYardage.innerText = course.Holes[i - 1].Length;
holePar.innerText = course.Holes[i - 1].Par;
yardSum += course.Holes[i - 1].Length;
}
document.getElementById("par-sum").innerText = course.Par;
document.getElementById("yard-sum").innerText = yardSum;
}
}
});
});
$("#save").click(function () {
console.log("numHoles: " + $("#numHoles").val());
console.log("score: " + $("#score").val());
console.log("putts: " + $("#putts").val());
console.log("uad: " + $("#uad").val());
console.log("ss: " + $("#ss").val());
});
$("#scores-array").change(function () {
var score;
var sum = 0;
var numHoles = 0;
for (var i = 1; i < 19; i++) {
if (parseInt($("#tb-h" + i).val()) > 0) {
numHoles++;
}
score = $("#tb-h" + i);
sum += parseInt(score.val());
}
document.getElementById("score-sum").innerText = sum;
$("#score").val(sum);
$("#numHoles").val(numHoles);
});
$("#putts-array").change(function () {
var putts;
var sum = 0;
for (var i = 1; i < 19; i++) {
putts = $("#tb-p" + i);
sum += parseInt(putts.val());
}
document.getElementById("putts-sum").innerText = sum;
$("#putts").val(sum);
});
$("#uad-array").change(uadEval);
$("#ss-array").change(function () {
var sum = 0;
for (var i = 1; i < 19; i++) {
if ($("#chb-ss" + i).is(":checked")) {
sum++;
}
}
document.getElementById("ss-sum").innerText = sum;
$("#ss").val(sum);
});
$("#chb-ss1").change(function () {
if ($("#chb-ss1").is(":checked")) {
$("#chb-uad1").prop("checked", true);
$("#chb-uad1").prop("disabled", true);
}
else {
$("#chb-uad1").prop("checked", false);
$("#chb-uad1").prop("disabled", false);
}
uadEval();
});
$("#chb-ss2").change(function () {
if ($("#chb-ss2").is(":checked")) {
$("#chb-uad2").prop("checked", true);
$("#chb-uad2").prop("disabled", true);
}
else {
$("#chb-uad2").prop("checked", false);
$("#chb-uad2").prop("disabled", false);
}
uadEval();
});
$("#chb-ss3").change(function () {
if ($("#chb-ss3").is(":checked")) {
$("#chb-uad3").prop("checked", true);
$("#chb-uad3").prop("disabled", true);
}
else {
$("#chb-uad3").prop("checked", false);
$("#chb-uad3").prop("disabled", false);
}
uadEval();
});
$("#chb-ss4").change(function () {
if ($("#chb-ss4").is(":checked")) {
$("#chb-uad4").prop("checked", true);
$("#chb-uad4").prop("disabled", true);
}
else {
$("#chb-uad4").prop("checked", false);
$("#chb-uad4").prop("disabled", false);
}
uadEval();
});
$("#chb-ss5").change(function () {
if ($("#chb-ss5").is(":checked")) {
$("#chb-uad5").prop("checked", true);
$("#chb-uad5").prop("disabled", true);
}
else {
$("#chb-uad5").prop("checked", false);
$("#chb-uad5").prop("disabled", false);
}
uadEval();
});
$("#chb-ss6").change(function () {
if ($("#chb-ss6").is(":checked")) {
$("#chb-uad6").prop("checked", true);
$("#chb-uad6").prop("disabled", true);
}
else {
$("#chb-uad6").prop("checked", false);
$("#chb-uad6").prop("disabled", false);
}
uadEval();
});
$("#chb-ss7").change(function () {
if ($("#chb-ss7").is(":checked")) {
$("#chb-uad7").prop("checked", true);
$("#chb-uad7").prop("disabled", true);
}
else {
$("#chb-uad7").prop("checked", false);
$("#chb-uad7").prop("disabled", false);
}
uadEval();
});
$("#chb-ss8").change(function () {
if ($("#chb-ss8").is(":checked")) {
$("#chb-uad8").prop("checked", true);
$("#chb-uad8").prop("disabled", true);
}
else {
$("#chb-uad8").prop("checked", false);
$("#chb-uad8").prop("disabled", false);
}
uadEval();
});
$("#chb-ss9").change(function () {
if ($("#chb-ss9").is(":checked")) {
$("#chb-uad9").prop("checked", true);
$("#chb-uad9").prop("disabled", true);
}
else {
$("#chb-uad9").prop("checked", false);
$("#chb-uad9").prop("disabled", false);
}
uadEval();
});
$("#chb-ss10").change(function () {
if ($("#chb-ss10").is(":checked")) {
$("#chb-uad10").prop("checked", true);
$("#chb-uad10").prop("disabled", true);
}
else {
$("#chb-uad10").prop("checked", false);
$("#chb-uad10").prop("disabled", false);
}
uadEval();
});
$("#chb-ss11").change(function () {
if ($("#chb-ss11").is(":checked")) {
$("#chb-uad11").prop("checked", true);
$("#chb-uad11").prop("disabled", true);
}
else {
$("#chb-uad11").prop("checked", false);
$("#chb-uad11").prop("disabled", false);
}
uadEval();
});
$("#chb-ss12").change(function () {
if ($("#chb-ss12").is(":checked")) {
$("#chb-uad12").prop("checked", true);
$("#chb-uad12").prop("disabled", true);
}
else {
$("#chb-uad12").prop("checked", false);
$("#chb-uad12").prop("disabled", false);
}
uadEval();
});
$("#chb-ss13").change(function () {
if ($("#chb-ss13").is(":checked")) {
$("#chb-uad13").prop("checked", true);
$("#chb-uad13").prop("disabled", true);
}
else {
$("#chb-uad13").prop("checked", false);
$("#chb-uad13").prop("disabled", false);
}
uadEval();
});
$("#chb-ss14").change(function () {
if ($("#chb-ss14").is(":checked")) {
$("#chb-uad14").prop("checked", true);
$("#chb-uad14").prop("disabled", true);
}
else {
$("#chb-uad14").prop("checked", false);
$("#chb-uad14").prop("disabled", false);
}
uadEval();
});
$("#chb-ss15").change(function () {
if ($("#chb-ss15").is(":checked")) {
$("#chb-uad15").prop("checked", true);
$("#chb-uad15").prop("disabled", true);
}
else {
$("#chb-uad15").prop("checked", false);
$("#chb-uad15").prop("disabled", false);
}
uadEval();
});
$("#chb-ss16").change(function () {
if ($("#chb-ss16").is(":checked")) {
$("#chb-uad16").prop("checked", true);
$("#chb-uad16").prop("disabled", true);
}
else {
$("#chb-uad16").prop("checked", false);
$("#chb-uad16").prop("disabled", false);
}
uadEval();
});
$("#chb-ss17").change(function () {
if ($("#chb-ss17").is(":checked")) {
$("#chb-uad17").prop("checked", true);
$("#chb-uad17").prop("disabled", true);
}
else {
$("#chb-uad17").prop("checked", false);
$("#chb-uad17").prop("disabled", false);
}
uadEval();
});
$("#chb-ss18").change(function () {
if ($("#chb-ss18").is(":checked")) {
$("#chb-uad18").prop("checked", true);
$("#chb-uad18").prop("disabled", true);
}
else {
$("#chb-uad18").prop("checked", false);
$("#chb-uad18").prop("disabled", false);
}
uadEval();
});
function uadEval() {
var sum = 0;
for (var i = 1; i < 19; i++) {
if ($("#chb-uad" + i).is(":checked")) {
sum++;
}
}
document.getElementById("uad-sum").innerText = sum;
$("#uad").val(sum);
}
});
</script>
}
I used to do the trick with jquery serialize by unhidden all fields before you getting the value and hide it back after everything complete.
I found the issue. For some reason the HTML hidden() helper functions did not have the correct names for the model binding. I think it worked before because the structure of the viewmodel was different, and when I updated the viewmodel the "name" attributes of the hidden fields weren't pointing to valid variables anymore.

Cannot remove padding in table

I am trying to remove the padding from the cells inside my table. I have set it to not have padding in the relevant CSS selectors but not a success.
As you can see, there is padding on all of these cells.
I would like there to not be. I have tried various different padding settings and changing the vertical alignment makes no difference other than to move the text, the padding just goes from all at the bottom to spread between bottom and top.
Below is the code:
'use strict'
let table = document.getElementById("mainTable")
let rows = table.querySelectorAll("tbody tr")
let columns = table.querySelectorAll("#weeks th")
for (let row of rows) {
for (let o = 0; o<columns.length-1; o++) {
let cell = document.createElement("td")
cell.innerHTML='&nbsp'
cell.addEventListener("click", function() {
if (cell.getElementsByTagName("input")[0]) { return } //If cell currently has an input box
//
let oldValue = ""
if (cell.innerHTML !== " ") { //if cell has a saved value
oldValue = cell.innerHTML
}
cell.innerHTML = '<input type="text" class="cellInputs">'
//update input box with old value and focus it
cell.getElementsByTagName("input")[0].focus()
cell.getElementsByTagName("input")[0].value = oldValue
cell.getElementsByTagName("input")[0].addEventListener("keypress", function(e) {
if (e.keyCode === 13) {
cell.innerHTML=cell.getElementsByTagName("input")[0].value
e.preventDefault()
return true
}
})
cell.getElementsByTagName("input")[0].addEventListener("input", function(e) {
console.log(e)
let cellValue = cell.getElementsByTagName("input")[0].value
if (e.data === "." && (cellValue.split('.').length-1 > 1 || cellValue === ".")) {
console.log("stop")
cell.getElementsByTagName("input")[0].value = (cellValue).substring(0, cellValue.length - e.data.length)
}
if (isNaN(e.data) && e.data !==".") {
console.log("Stop")
cell.getElementsByTagName("input")[0].value = (cellValue).substring(0, cellValue.length - e.data.length)
}
//store value inputted into the actual cell
})
cell.getElementsByTagName("input")[0].addEventListener("paste", function(e) {
// clipboardData = e.clipboardData || window.clipboardData;
// pastedData = clipboardData.getData('Text');
let cellValue = cell.getElementsByTagName("input")[0].value
if (cellValue !== "") {
e.preventDefault()
return false
}
if (e.clipboardData.getData('text') === "." && (cellValue.split('.').length-1 > 1 || cellValue === ".")) {
e.preventDefault()
return false
}
if (isNaN(e.clipboardData.getData('text')) && e.clipboardData.getData('text') !==".") {
e.preventDefault()
return false
}
//store value inputted into the actual cell
})
cell.getElementsByTagName("input")[0].addEventListener("focusout", function() {
console.log(document.activeElement)
cell.innerHTML=cell.getElementsByTagName("input")[0].value
})
})
row.appendChild(cell)
}
}
*{
padding: 0;
margin: 0;
font-family: "Trebuchet MS", Times, serif;
box-sizing:border-box;
}
html{
background-color: #35454E;
overflow: hidden;
}
html *{
font-family: "Work Sans", Arial, sans-serif !important;
color: white !important;
}
table{
border-collapse: collapse;
border-spacing: 0px;
color:#35454E;
height:100%;
width:100%;
}
table, th{
border: 2px solid white;
padding:0;
}
th{
vertical-align:top;
font-size: 2.5vw;
}
td{
vertical-align:top;
box-sizing:border-box;
position: relative;
border: 2px solid white;
padding:0;
text-align: center;
font-size: 2.5vw;
padding:0;
}
.cellInputs{
position: absolute;
width:100%;
height:100%;
display: block;
top:0;
left:0;
border:none;
text-align: center;
background-color: #35454E;
word-wrap: break-word;
font-size: 2.5vw;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="MMS.css">
<title>Money Management</title>
</head>
<body>
<table id="mainTable">
<thead>
<tr>
<th>2019</th>
<th colspan="5">January</th>
</tr>
<tr id="weeks">
<th>&nbsp</th>
<th>31/12/2018</th>
<th>07/01/2019</th>
<th>14/01/2019</th>
<th>21/01/2019</th>
<th>28/01/2019</th>
</tr>
</thead>
<tbody>
<tr>
<th>Balance</th>
</tr>
<tr>
<th>Pay</th>
</tr>
<tr>
<th>&nbsp</th>
</tr>
<tr>
<th>Rent</th>
</tr>
<tr>
<th>Food</th>
</tr>
<tr>
<th>&nbsp</th>
</tr>
<tr>
<th>Total</th>
</tr>
</tbody>
</table>
</body>
<script src="MMS.js"></script>
</html>
Remove height:100% from table .

Space between two columns in a table?

I am using data table for displaying data from the database. There is no space between two columns of the data table. How to add space between them. I tried few codes but with no luck...
<html dir="rtl">
<title>moviewall</title>
<style>
#font-face { font-family: "Alef Regular"; src: url("https://s3.eu-central-1.amazonaws.com/moviewall/Alef-Regular.ttf"); }
body { font-family: "Alef Regular", serif }
margin: 0;
font-size: 500%;
font-family: "Alef Regular";
color: white;
line-height: 2.7;
}
</style>
<div id="content"><div dir="ltr">Loading...</div></div>
<script src="lib.js"></script>
<script>
function getHead() {
var row = document.createElement('tr');
['Movie', 'Hall', 'Time'].forEach(function (text) {
var column = document.createElement('th');
column.appendChild(document.createTextNode(text));
row.appendChild(column);
});
return row;
}
function getRow(item) {
var row = document.createElement('tr');
['time', 'hall', 'movie'].forEach(function (property) {
var column = document.createElement('td');
column.appendChild(document.createTextNode(item[property]));
row.appendChild(column);
});
return row;
}
function refreshData() {
var content = document.getElementById('content');
getAllData(function (data) {
clear(content);
var table = document.createElement('table');
table.appendChild(getHead());
data
.filter(function (item) {
var date = new Date();
var minutes1 = date.getHours() * 60 + date.getMinutes();
var minutes2 = convertTimeToMinutes(item.time);
return minutes2 >= minutes1 && minutes2 <= minutes1 + 120;
})
.forEach(function (item) {
table.appendChild(getRow(item));
});
content.appendChild(table);
});
}
setInterval(refreshData, getInterval());
refreshData();
</script>
Blockquote
How can i add space or gap between the columns tr text? 'time', 'hall', 'movie'
Right now they are attached to each other...
Thanks a lot
Shlomi
if you need padding around texts:
td {
padding: 10px;
}
If you want real space between table cells:
td {
border-spacing: 5px;
}
Use border-spacing, see example below:
table {
border-collapse: separate;
border-spacing: 30px 0;
}
td {
border: 1px solid red;
padding: 20px 0;
}
<table>
<tr>
<td>1st column</td>
<td>2nd column</td>
<td>3rd column</td>
<td>4th column</td>
</tr>
</table>

grey border surrounding image

I have a Bootstrap table on the view and the last 2 columns are images. I load the table once the Ajax call is successful.
Issue
when table id populated with data, I see grey border and nothing makes sense. I don't have any code which specifies border.
Below is my CSS Code
img {
border:none;
}
table {
border-collapse:collapse;
}
.assign {
background: url(Images/user_not_assigned.png) no-repeat;
width:100%;
height:40px;
}
I added blue dashed border to the image to make sure it overrides. I see the blue dashed border along with grey border
CSS
img {
border : 2px blue dashed;
border-radius:10px;
padding:5px;
}
table {
border-collapse:collapse;
}
.assign {
background: url(Images/user_not_assigned.png) no-repeat;
width:100%;
height:40px;
}
HTML View:
<div id="getorder" class="table-responsive" data-request-url="#Url.Action("GetPendingOrders", "Main")">
<table id="editorder" class="table table-striped table-hover">
<caption><h4 class="chocolatetext"><strong>Pending / Assigned Orders</strong></h4></caption>
<thead>
<tr>
<th>COL1 #</th>
<th>COL2 #</th>
<th>COL3 #</th>
<th>Assign</th>
<th>Update</th>
</tr>
</thead>
<tbody id="assignorder" data-request-url="#Url.Action("AssignOrder", "Main")">
</tbody>
</table>
</div>
#Scripts.Render("~/Scripts/Custom/main.js")
Jquery Code to load table
$.ajax({
type: 'GET',
url: peningorderurl,
traditional: true,
cache: false,
success: function (data) {
var table = $("table");
table.find("tr:gt(0)").remove(); //remove all previous rows if needed
$.each(data, function (index, element) {
var tr = $("<tr class='clickable-row' data-href=" + element.id + " data-row=" + element.orderno + "></tr>");
table.append(tr);
var td = $("<td>" + element.id + "</td>");
tr.append(td);
var td = $("<td class='testno'>" + element.testno + "</td>");
tr.append(td);
var td = $("<td class='screenno'>" + element.screenno + "</td>");
tr.append(td);
var assignimage = ('<img class="assign assignselected" alt:"Assign Image" />');
if (element.assigned == true) {
assignimage = ('<img class="assigned assignselected" alt:"Assign Image" />');
}
var td = $("<td>" + assignimage + "</td>");
tr.append(td);
assignimage = ('<img class="no-testresults editselected" alt:"Update Test Results" />');
var td = $("<td>" + assignimage + "</td>");
tr.append(td);
});
},
error: function (err) {
alert("Ajax failed:");
console.log(err);
}
});
Question
How do I remove this grey border? Any help would be appreciated.
Change your table CSS to:
table {
border:0;
}
add border 0 on table
table {
border-collapse:collapse;
border:0;
}
Could be background colour coming through?
td {
background-color: #fff;
padding: 0;
}
img {
margin: 0;
display: block;
}
Try using exact specificity for that vs just targeting the table, so try this:
table thead > tr > th { border: none; }
I had the same issue and finally figured it out. The combination of an img Tag and the background property causes this issue. Either use the img tag with src= or use another tag.
Answer found here: css "background-image" shows unwanted border, img "src" does not

my script is working on jfiddle only but not on local machine

I have a codes on Jsfiddle but not showing on realtime project i have consider external resources. Jfiddle has a tab menu and each tab is showing different chart on it like bar chart or pie chart or line chart.
I put both the css and js files on same page and also on the different page than also its not showing the js function on other tab.
Please let me know the solution i am trying from very long but its not working.
Jsfiddle
<div id="TabbedPanels1" class="TabbedPanels">
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsTab" tabindex="0">Tab 1</li>
<li class="TabbedPanelsTab" tabindex="0">Tab 2</li>
</ul>
<div class="TabbedPanelsContentGroup">
<div class="TabbedPanelsContent">
<div id="jQueryVisualizeChart1"></div>
<br />
<table id="table1">
<caption>2010 Employee Sales by Department</caption>
<thead>
<tr>
<td></td>
<th scope="col">food</th>
<th scope="col">auto</th>
<th scope="col">household</th>
<th scope="col">furniture</th>
<th scope="col">kitchen</th>
<th scope="col">bath</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Mary</th>
<td>190</td>
<td>160</td>
<td>40</td>
<td>120</td>
<td>30</td>
<td>70</td>
</tr>
<tr>
<th scope="row">Tom</th>
<td>3</td>
<td>40</td>
<td>30</td>
<td>45</td>
<td>35</td>
<td>49</td>
</tr>
</tbody>
</table>
</div>
<div class="TabbedPanelsContent">
<div id="jQueryVisualizeChart2"></div>
<br />
<table id="table2">
<caption>2010 Employee Sales by Department</caption>
<thead>
<tr>
<td></td>
<th scope="col">food</th>
<th scope="col">auto</th>
<th scope="col">household</th>
<th scope="col">furniture</th>
<th scope="col">kitchen</th>
<th scope="col">bath</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Mary</th>
<td>190</td>
<td>160</td>
<td>40</td>
<td>120</td>
<td>30</td>
<td>70</td>
</tr>
<tr>
<th scope="row">Tom</th>
<td>3</td>
<td>40</td>
<td>30</td>
<td>45</td>
<td>35</td>
<td>49</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
(function () { // BeginSpryComponent
if (typeof Spry == "undefined") window.Spry = {};
if (!Spry.Widget) Spry.Widget = {};
Spry.Widget.TabbedPanels = function (element, opts) {
this.element = this.getElement(element);
this.defaultTab = 0; // Show the first panel by default.
this.tabSelectedClass = "TabbedPanelsTabSelected";
this.tabHoverClass = "TabbedPanelsTabHover";
this.tabFocusedClass = "TabbedPanelsTabFocused";
this.panelVisibleClass = "TabbedPanelsContentVisible";
this.focusElement = null;
this.hasFocus = false;
this.currentTabIndex = 0;
this.enableKeyboardNavigation = true;
this.nextPanelKeyCode = Spry.Widget.TabbedPanels.KEY_RIGHT;
this.previousPanelKeyCode = Spry.Widget.TabbedPanels.KEY_LEFT;
Spry.Widget.TabbedPanels.setOptions(this, opts);
if (typeof (this.defaultTab) == "number") {
if (this.defaultTab < 0) this.defaultTab = 0;
else {
var count = this.getTabbedPanelCount();
if (this.defaultTab >= count) this.defaultTab = (count > 1) ? (count - 1) : 0;
}
this.defaultTab = this.getTabs()[this.defaultTab];
}
if (this.defaultTab) this.defaultTab = this.getElement(this.defaultTab);
this.attachBehaviors();
};
Spry.Widget.TabbedPanels.prototype.getElement = function (ele) {
if (ele && typeof ele == "string") return document.getElementById(ele);
return ele;
};
Spry.Widget.TabbedPanels.prototype.getElementChildren = function (element) {
var children = [];
var child = element.firstChild;
while (child) {
if (child.nodeType == 1 /* Node.ELEMENT_NODE */ ) children.push(child);
child = child.nextSibling;
}
return children;
};
Spry.Widget.TabbedPanels.prototype.addClassName = function (ele, className) {
if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1)) return;
ele.className += (ele.className ? " " : "") + className;
};
Spry.Widget.TabbedPanels.prototype.removeClassName = function (ele, className) {
if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1)) return;
ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};
Spry.Widget.TabbedPanels.setOptions = function (obj, optionsObj, ignoreUndefinedProps) {
if (!optionsObj) return;
for (var optionName in optionsObj) {
if (ignoreUndefinedProps && optionsObj[optionName] == undefined) continue;
obj[optionName] = optionsObj[optionName];
}
};
Spry.Widget.TabbedPanels.prototype.getTabGroup = function () {
if (this.element) {
var children = this.getElementChildren(this.element);
if (children.length) return children[0];
}
return null;
};
Spry.Widget.TabbedPanels.prototype.getTabs = function () {
var tabs = [];
var tg = this.getTabGroup();
if (tg) tabs = this.getElementChildren(tg);
return tabs;
};
Spry.Widget.TabbedPanels.prototype.getContentPanelGroup = function () {
if (this.element) {
var children = this.getElementChildren(this.element);
if (children.length > 1) return children[1];
}
return null;
};
Spry.Widget.TabbedPanels.prototype.getContentPanels = function () {
var panels = [];
var pg = this.getContentPanelGroup();
if (pg) panels = this.getElementChildren(pg);
return panels;
};
Spry.Widget.TabbedPanels.prototype.getIndex = function (ele, arr) {
ele = this.getElement(ele);
if (ele && arr && arr.length) {
for (var i = 0; i < arr.length; i++) {
if (ele == arr[i]) return i;
}
}
return -1;
};
Spry.Widget.TabbedPanels.prototype.getTabIndex = function (ele) {
var i = this.getIndex(ele, this.getTabs());
if (i < 0) i = this.getIndex(ele, this.getContentPanels());
return i;
};
Spry.Widget.TabbedPanels.prototype.getCurrentTabIndex = function () {
return this.currentTabIndex;
};
Spry.Widget.TabbedPanels.prototype.getTabbedPanelCount = function (ele) {
return Math.min(this.getTabs().length, this.getContentPanels().length);
};
Spry.Widget.TabbedPanels.addEventListener = function (element, eventType, handler, capture) {
try {
if (element.addEventListener) element.addEventListener(eventType, handler, capture);
else if (element.attachEvent) element.attachEvent("on" + eventType, handler);
} catch (e) {}
};
Spry.Widget.TabbedPanels.prototype.cancelEvent = function (e) {
if (e.preventDefault) e.preventDefault();
else e.returnValue = false;
if (e.stopPropagation) e.stopPropagation();
else e.cancelBubble = true;
return false;
};
Spry.Widget.TabbedPanels.prototype.onTabClick = function (e, tab) {
this.showPanel(tab);
return this.cancelEvent(e);
};
Spry.Widget.TabbedPanels.prototype.onTabMouseOver = function (e, tab) {
this.addClassName(tab, this.tabHoverClass);
return false;
};
Spry.Widget.TabbedPanels.prototype.onTabMouseOut = function (e, tab) {
this.removeClassName(tab, this.tabHoverClass);
return false;
};
Spry.Widget.TabbedPanels.prototype.onTabFocus = function (e, tab) {
this.hasFocus = true;
this.addClassName(tab, this.tabFocusedClass);
return false;
};
Spry.Widget.TabbedPanels.prototype.onTabBlur = function (e, tab) {
this.hasFocus = false;
this.removeClassName(tab, this.tabFocusedClass);
return false;
};
Spry.Widget.TabbedPanels.KEY_UP = 38;
Spry.Widget.TabbedPanels.KEY_DOWN = 40;
Spry.Widget.TabbedPanels.KEY_LEFT = 37;
Spry.Widget.TabbedPanels.KEY_RIGHT = 39;
Spry.Widget.TabbedPanels.prototype.onTabKeyDown = function (e, tab) {
var key = e.keyCode;
if (!this.hasFocus || (key != this.previousPanelKeyCode && key != this.nextPanelKeyCode)) return true;
var tabs = this.getTabs();
for (var i = 0; i < tabs.length; i++)
if (tabs[i] == tab) {
var el = false;
if (key == this.previousPanelKeyCode && i > 0) el = tabs[i - 1];
else if (key == this.nextPanelKeyCode && i < tabs.length - 1) el = tabs[i + 1];
if (el) {
this.showPanel(el);
el.focus();
break;
}
}
return this.cancelEvent(e);
};
Spry.Widget.TabbedPanels.prototype.preorderTraversal = function (root, func) {
var stopTraversal = false;
if (root) {
stopTraversal = func(root);
if (root.hasChildNodes()) {
var child = root.firstChild;
while (!stopTraversal && child) {
stopTraversal = this.preorderTraversal(child, func);
try {
child = child.nextSibling;
} catch (e) {
child = null;
}
}
}
}
return stopTraversal;
};
Spry.Widget.TabbedPanels.prototype.addPanelEventListeners = function (tab, panel) {
var self = this;
Spry.Widget.TabbedPanels.addEventListener(tab, "click", function (e) {
return self.onTabClick(e, tab);
}, false);
Spry.Widget.TabbedPanels.addEventListener(tab, "mouseover", function (e) {
return self.onTabMouseOver(e, tab);
}, false);
Spry.Widget.TabbedPanels.addEventListener(tab, "mouseout", function (e) {
return self.onTabMouseOut(e, tab);
}, false);
if (this.enableKeyboardNavigation) {
var tabIndexEle = null;
var tabAnchorEle = null;
this.preorderTraversal(tab, function (node) {
if (node.nodeType == 1 /* NODE.ELEMENT_NODE */ ) {
var tabIndexAttr = tab.attributes.getNamedItem("tabindex");
if (tabIndexAttr) {
tabIndexEle = node;
return true;
}
if (!tabAnchorEle && node.nodeName.toLowerCase() == "a") tabAnchorEle = node;
}
return false;
});
if (tabIndexEle) this.focusElement = tabIndexEle;
else if (tabAnchorEle) this.focusElement = tabAnchorEle;
if (this.focusElement) {
Spry.Widget.TabbedPanels.addEventListener(this.focusElement, "focus", function (e) {
return self.onTabFocus(e, tab);
}, false);
Spry.Widget.TabbedPanels.addEventListener(this.focusElement, "blur", function (e) {
return self.onTabBlur(e, tab);
}, false);
Spry.Widget.TabbedPanels.addEventListener(this.focusElement, "keydown", function (e) {
return self.onTabKeyDown(e, tab);
}, false);
}
}
};
Spry.Widget.TabbedPanels.prototype.showPanel = function (elementOrIndex) {
var tpIndex = -1;
if (typeof elementOrIndex == "number") tpIndex = elementOrIndex;
else // Must be the element for the tab or content panel.
tpIndex = this.getTabIndex(elementOrIndex);
if (!tpIndex < 0 || tpIndex >= this.getTabbedPanelCount()) return;
var tabs = this.getTabs();
var panels = this.getContentPanels();
var numTabbedPanels = Math.max(tabs.length, panels.length);
for (var i = 0; i < numTabbedPanels; i++) {
if (i != tpIndex) {
if (tabs[i]) this.removeClassName(tabs[i], this.tabSelectedClass);
if (panels[i]) {
this.removeClassName(panels[i], this.panelVisibleClass);
panels[i].style.display = "none";
}
}
}
this.addClassName(tabs[tpIndex], this.tabSelectedClass);
this.addClassName(panels[tpIndex], this.panelVisibleClass);
panels[tpIndex].style.display = "block";
this.currentTabIndex = tpIndex;
};
Spry.Widget.TabbedPanels.prototype.attachBehaviors = function (element) {
var tabs = this.getTabs();
var panels = this.getContentPanels();
var panelCount = this.getTabbedPanelCount();
for (var i = 0; i < panelCount; i++)
this.addPanelEventListeners(tabs[i], panels[i]);
this.showPanel(this.defaultTab);
};
})();
$(function () {
$('#table1').visualize({
type: 'bar',
height: '260px',
width: '420px',
appendTitle: true,
lineWeight: 4,
colors: ['#be1e2d', '#666699', '#92d5ea', '#ee8310', '#8d10ee', '#5a3b16', '#26a4ed', '#f45a90', '#e9e744']
}).appendTo('#jQueryVisualizeChart').trigger('visualizeRefresh1');
});
$(function () {
$('#table2').visualize({
type: 'line',
height: '300px',
width: '420px',
appendTitle: true,
lineWeight: 4,
colors: ['#be1e2d', '#666699', '#92d5ea', '#ee8310', '#8d10ee', '#5a3b16', '#26a4ed', '#f45a90', '#e9e744']
}).appendTo('#jQueryVisualizeChart').trigger('visualizeRefresh2');
});
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
.dwpeAd {
color: #333;
background-color: #F4F3Ea;
position:fixed;
right: 20px;
top: 20px;
padding: 5px;
}
.visualize {
margin: 20px 0 0 30px;
}
.TabbedPanels {
overflow: hidden;
margin: 0px;
padding: 0px;
clear: none;
width: 100%;
}
.TabbedPanelsTabGroup {
margin: 0px;
padding: 0px;
}
.TabbedPanelsTab {
position: relative;
top: 1px;
float: left;
padding: 4px 10px;
margin: 0px 1px 0px 0px;
font: bold 0.7em sans-serif;
background-color: #DDD;
list-style: none;
border-left: solid 1px #CCC;
border-bottom: solid 1px #999;
border-top: solid 1px #999;
border-right: solid 1px #999;
-moz-user-select: none;
-khtml-user-select: none;
cursor: pointer;
}
.TabbedPanelsTabHover {
background-color: #CCC;
}
.TabbedPanelsTabSelected {
background-color: #EEE;
border-bottom: 1px solid #EEE;
}
.TabbedPanelsTab a {
color: black;
text-decoration: none;
}
.TabbedPanelsContentGroup {
clear: both;
border-left: solid 1px #CCC;
border-bottom: solid 1px #CCC;
border-top: solid 1px #999;
border-right: solid 1px #999;
background-color: #EEE;
}
.TabbedPanelsContent {
overflow: hidden;
padding: 4px;
}
.TabbedPanelsContentVisible {
}
.VTabbedPanels {
overflow: hidden;
zoom: 1;
}
.VTabbedPanels .TabbedPanelsTabGroup {
float: left;
width: 10em;
height: 20em;
background-color: #EEE;
position: relative;
border-top: solid 1px #999;
border-right: solid 1px #999;
border-left: solid 1px #CCC;
border-bottom: solid 1px #CCC;
}
.VTabbedPanels .TabbedPanelsTab {
float: none;
margin: 0px;
border-top: none;
border-left: none;
border-right: none;
}
.VTabbedPanels .TabbedPanelsTabSelected {
background-color: #EEE;
border-bottom: solid 1px #999;
}
.VTabbedPanels .TabbedPanelsContentGroup {
clear: none;
float: left;
padding: 0px;
width: 30em;
height: 20em;
}
/* Styles for Printing */
#media print {
.TabbedPanels {
overflow: visible !important;
}
.TabbedPanelsContentGroup {
display: block !important;
overflow: visible !important;
height: auto !important;
}
.TabbedPanelsContent {
overflow: visible !important;
display: block !important;
clear:both !important;
}
.TabbedPanelsTab {
overflow: visible !important;
display: block !important;
clear:both !important;
}
}
I think you did not copy the 'external resources' on left menu.