I am trying to get the polarity variable, and change the color of that row depending on the value, for example, 1,2 and 3. Any ideas of how i could do this. I tried this, but it is not working. Thankyou.
$("#tableView").click(function(event){
$('#empty').html('');
$('#empty').show();
$('.content').addClass('hide');
var tweet;
var i;
$('#empty').append('<div><table><tr><th>Tweet</th><th>Polarity</th></tr></table></div>');
$('.tab-content > .active span').each(function() {
tweet = $(this).text().slice(0,-2);
var polarity = $(this).find('.change').text();
$('table').append('<tr><td>'+ tweet + '</td><td>'+ polarity + '</td></tr>');
if($('polarity:contains("1")').css('background-color', 'red'));
});
});
This is html where i am getting the data from database using PHP, and setting a button to show the data.
<div class="parliamentContainer">
<h1>Parliament</h1>
<ul class="nav nav-tabs">
<li class="active"></li>
<li><a data-toggle="tab" href="#bbc">BBC Parliament</a></li>
<li><a data-toggle="tab" href="#minister">Ministers</a></li>
<li><a data-toggle="tab" href="#law">Law</a></li>
<li><a data-toggle="tab" href="#crime">Crime</a></li>
<li><a data-toggle="tab" href="#seeAllPar">See All</a></li>
</ul>
<div class="tab-content">
<button type="button" id="tableView"> Show in table form</button>
<div id= "empty"></div>
<div class="content tab-pane fade" id = "bbc">
<?php
$result = mysql_query("SELECT * FROM parliament WHERE tweet LIKE '%bbc%';",$db);
if (!$result) {
die("Database query failed: " . mysql_error());
}
while ($row = mysql_fetch_array($result)) {
echo "<span>".$row[0]. "<p class='change'>".$row[1]."</p> </span>";
}
?>
</div>
This is the table element, within my html.
<style>
table, td, th {
border: 1px solid #ddd;
text-align: left;
}
table {
border-collapse: collapse;
width: 40%;
}
th, td {
padding: 10px;
}
</style>