This is related to my original Question, which was solved: JavaScript show/hide divs
So I have gone with Fadi's answer on the original question and it works perfectly. How would I be able to use two div's for the same data-collaboration category?
I want to have teams show up under "Collaborate Socially" and "Collaborate on Files" - the categories "project, files, socially" are all using the data-decision definition.
I've tried adding two data-decision="projects" data-decision="socially" in one div and it didn't work.
<div class="outer-container">
<div class="row">
<div class="col-md-4" style="text-align: center;">
<div data-collaborate="projects" class="decisionTreeBox collabProjects" style="font-size: x-large;">
Collaborate on Projects</div>
</div>
<div class="col-md-4" style="text-align: center;">
<div data-collaborate="files" class="decisionTreeBox collabFiles" style="font-size: x-large;">
Collaborate on Files</div>
</div>
<div class="col-md-4" style="text-align: center;">
<div data-collaborate="socially" class="decisionTreeBox collabSocially" style="font-size: x-large;">
Collaborate Socially</div>
</div>
</div>
<hr />
<div class="container" style="padding: 0px;">
<div class="row">
<a href="/TrainingResourceCenter/O365Training/Pages/OneDrive.aspx"><div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="files" id="decisionTreeOneDrive"><h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/onedrive-logo.png" style="width: 65px; height: 65px; padding-bottom: 5px; padding-right: 10px; vertical-align: middle;"/>OneDrive</h3></div>
</div></a>
<!-- <a href="/TrainingResourceCenter/O365Training/Pages/O365.aspx"><div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="projects" id="decisionTreeProject"><h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/Project.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;"/>Project</h3></div>
</div></a> -->
<a href="/TrainingResourceCenter/O365Training/Pages/SharePointOnline.aspx"><div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="files" id="decisionTreeSharePoint"><h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/SharePointDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;"/>SharePoint</h3></div>
</div></a>
<a href="/TrainingResourceCenter/O365Training/Pages/Teams.aspx"><div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="socially" id="decisionTreeTeams"><h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/TeamsDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;"/>Teams</h3></div>
</div></a>
<a href="/TrainingResourceCenter/O365Training/Pages/Planner.aspx"><div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="projects" id="decisionTreePlanner"><h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/PlannerDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;"/>Planner</h3></div>
</div></a>
<a href="/TrainingResourceCenter/O365Training/Pages/Yammer.aspx"><div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="socially" id="decisionTreeYammer"><h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/YammerDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;"/>Yammer</h3></div>
</div></a>
</div>
</div>
</div>
<script>
function projectCollab(){
var divsToCange = document.querySelectorAll('[data-decision]'),
attr = this.getAttribute('data-collaborate');
for(var i = 0; i < divsToCange.length; i++){
var d = divsToCange[i];
if(d.getAttribute('data-decision') == attr) {
d.parentNode.style.display ='block' ;
}
else{
d.parentNode.style.display = 'none';
}
}
return false;
}
var divButtons = document.querySelectorAll('[data-collaborate]');
for(var i = 0; i < divButtons.length; i++){
divButtons[i].addEventListener('click', projectCollab);
}
</script>
This fix comes easy once you have started with data attributes
2 sides of the solution
HTML
You will be able to stack the values separated by a space
data-decision="socially files"
JS
For the HTML to work, we will change your if statement where you checked if the data attribute was the same as the once selected. Now we are going to validate if the data attribute includes the once selected.
This was your if statement
if(d.getAttribute('data-decision') == attr)
This is the new if statement
if (d.getAttribute('data-decision').includes(attr))
Hope this helps :>
function projectCollab() {
var divsToCange = document.querySelectorAll('[data-decision]'),
attr = this.getAttribute('data-collaborate');
for (var i = 0; i < divsToCange.length; i++) {
var d = divsToCange[i];
if (d.getAttribute('data-decision').includes(attr)) {
d.parentNode.style.display = 'block';
} else {
d.parentNode.style.display = 'none';
}
}
return false;
}
var divButtons = document.querySelectorAll('[data-collaborate]');
for (var i = 0; i < divButtons.length; i++) {
divButtons[i].addEventListener('click', projectCollab);
}
<div class="outer-container">
<div class="row">
<div class="col-md-4" style="text-align: center;">
<div data-collaborate="projects" class="decisionTreeBox collabProjects" style="font-size: x-large;">
Collaborate on Projects</div>
</div>
<div class="col-md-4" style="text-align: center;">
<div data-collaborate="files" class="decisionTreeBox collabFiles" style="font-size: x-large;">
Collaborate on Files</div>
</div>
<div class="col-md-4" style="text-align: center;">
<div data-collaborate="socially" class="decisionTreeBox collabSocially" style="font-size: x-large;">
Collaborate Socially</div>
</div>
</div>
<hr />
<div class="container" style="padding: 0px;">
<div class="row">
<a href="/TrainingResourceCenter/O365Training/Pages/OneDrive.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="files" id="decisionTreeOneDrive">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/onedrive-logo.png" style="width: 65px; height: 65px; padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />OneDrive</h3>
</div>
</div>
</a>
<!-- <a href="/TrainingResourceCenter/O365Training/Pages/O365.aspx"><div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="projects" id="decisionTreeProject"><h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/Project.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;"/>Project</h3></div>
</div></a> -->
<a href="/TrainingResourceCenter/O365Training/Pages/SharePointOnline.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="files" id="decisionTreeSharePoint">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/SharePointDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />SharePoint</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/Teams.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="socially files" id="decisionTreeTeams">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/TeamsDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />Teams</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/Planner.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="projects" id="decisionTreePlanner">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/PlannerDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />Planner</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/Yammer.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="socially" id="decisionTreeYammer">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/YammerDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />Yammer</h3>
</div>
</div>
</a>
</div>
</div>
</div>
<script>
</script>
Related
Here is my code:
$('#hitung').click(function() {
var count = $('.item').length;
var locality = 'id-ID';
var luas = $('.tinggi' + count).val() * $('#lebar' + count).val();
console.log(luas);
var dayasebar = luas / 12.5 * 2;
var hasil = dayasebar / 2.5;
var harga = Math.ceil(hasil) * 120000;
var title = $('#title-temp').text();
var color = document.querySelector('input[name="color"]:checked').value;
var color_title = document.querySelector('input[name="color"]:checked ~ label h4').innerHTML;
$('#luas').html('<p>Luas: ' + luas + ' meter ²</p>');
$('#hasil').html('<p>' + Math.ceil(hasil) + ' Kaleng ' + Math.ceil(hasil) * 5 + ' Kg | Rp ' + harga.toLocaleString(locality, {}) + '</p>');
$('#color').html('<div class="row"><div class="col-xs-6 col-md-4" style="height: 50px; float: left; background-color: ' + color + '; display: block;text-align: center;"></div><div class="col-xs-6 col-md-8"><h4 style="text-transform: capitalize; font-weight: bold; margin-top:0">' + title + '</h4><p>' + color_title + '</p></div></div>');
$('.panel-footer').css('display', 'block');
});
$('#tambah').click(function() {
var count = $('.item').length;
var id = 'Item[' + count + ']';
var item = $('.item:first').clone();
// item.find('input:first').attr('id', id);
item.find('.tinggi' + count + ':first').attr('id', 'tinggi' + count);
item.find('#title:first').attr('for', id)
.html('Dinding ' + (1 + count));
item.appendTo('#fieldset');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="fieldset">
<div class="panel panel-default item" style="background-color: #f2f2f2;border-radius: 0;border: 0;">
<div class="panel-body">
<h3 id="title" style="text-transform: uppercase; font-weight: bold; text-decoration: underline; margin-bottom: 25px" class="text-center">Dinding 1</h3>
<form>
<div class="row text-left">
<div class="col-md-10 col-md-offset-1">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label style="font-style: italic; font-weight: normal; font-size: 20px">Tinggi</label>
<input type="text" id="tinggi1" name="tinggi" class="form-control new-input tinggi">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label style="font-style: italic; font-weight: normal; font-size: 20px">Lebar</label>
<input type="text" id="lebar1" name="lebar" class="form-control new-input">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label style="font-style: italic; font-weight: normal; font-size: 20px">Pilih Warna</label>
<div class="row">
<div class="col-md-12">
<div class="col-md-4" style="background-color: #fff;padding-top: 15px;padding-bottom: 12px;">
<div id="color-group1">
<input type="radio" name="color" id="color1" class="input-hidden" value="blue" data-name="Hello" style="visibility:hidden; display: none;" />
<label for="color1" style="display: block;">
<span style="width: 100%; background-color: blue; display: block;text-align: center;padding: 50px 0;">
<h4>Warna 1</h4>
</span>
</label>
</div>
</div>
<div class="col-md-4" style="background-color: #fff;padding-top: 15px;padding-bottom: 12px;">
<div id="color-group2">
<input type="radio" name="color" id="color2" class="input-hidden" value="lightblue" style="visibility:hidden; display: none;" />
<label for="color2" style="display: block;">
<span style="width: 100%; background-color: lightblue; display: block;text-align: center;padding: 50px 0;">
<h4>Warna 2</h4>
</span>
</label>
</div>
</div>
<div class="col-md-4" style="background-color: #fff;padding-top: 15px;padding-bottom: 12px;">
<div id="color-group3">
<input type="radio" name="color" id="color3" class="input-hidden" value="brown" style="visibility:hidden; display: none;" />
<label for="color3" style="display: block;">
<span style="width: 100%; background-color: brown; display: block;text-align: center;padding: 50px 0;">
<h4>Warna 3</h4>
</span>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="panel-footer quite-white-tip bg-pink text-white" style="display: none">
<h3 style="text-transform: uppercase; text-decoration: underline; font-weight: 600">Kebutuhan Cat Anda</h3><br>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="media">
<div class="row">
<div class="col-md-5">
<div class="media-left media-middle">
<a href="#">
<img class="media-object img-responsive" src="http://www.catster.com/wp-content/uploads/2017/08/A-fluffy-cat-looking-funny-surprised-or-concerned.jpg" alt="...">
</a>
</div>
</div>
<div class="col-md-7">
<div class="media-body text-left">
<div id="color" style="display: block; clear: both; width: 100%;"></div><br>
<div id="luas"></div>
<div id="hasil"></div>
<div id="title-temp" style="display: none;">Warna</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<button type="button" id="tambah" class="btn btn-sm btn-link">Add</button><br>
<button type="button" id="hitung" class="btn btn-lg btn-success">COUNT</button>
<br><br>
When I press COUNT button, the code working fine, all the result placed well on where I want it to be shown. But I still missing one feature, append the item class. When I append or add or clone item class, the calculation is not working due to the id or name of each input are same. I tried using [] for the input but still don't know how to count it and place all the result each just like the original element.
$('#hitung').click(function() {
var count = $('.item').length;
var locality = 'id-ID';
var luas = $('#tinggi' + count).val() * $('#lebar' + count).val();
var dayasebar = luas / 12.5 * 2;
var hasil = dayasebar / 2.5;
var harga = Math.ceil(hasil) * 120000;
var title = $('#title-temp').text();
var color = $('input[name=color]').css('backgroundColor');
var color_title =$('input[name=color] ~ label h4').text();
$('#luas').html('<p>Luas: ' + luas + ' meter ²</p>');
$('#hasil').html('<p>' + Math.ceil(hasil) + ' Kaleng ' + Math.ceil(hasil) * 5 + ' Kg | Rp ' + harga.toLocaleString(locality, {}) + '</p>');
$('#color').html('<div class="row"><div class="col-xs-6 col-md-4" style="height: 50px; float: left; background-color: ' + color + '; display: block;text-align: center;"></div><div class="col-xs-6 col-md-8"><h4 style="text-transform: capitalize; font-weight: bold; margin-top:0">' + title + '</h4><p>' + color_title + '</p></div></div>');
$('.panel-footer').css('display', 'block');
});
$('#tambah').click(function() {
var count = $('.item').length;
var id = 'Item[' + count + ']';
var item = $('.item:first').clone();
// item.find('input:first').attr('id', id);
item.find('.tinggi' + count + ':first').attr('id', 'tinggi' + count);
item.find('#title:first').attr('for', id)
.html('Dinding ' + (1 + count));
item.appendTo('#fieldset');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="fieldset">
<div class="panel panel-default item" style="background-color: #f2f2f2;border-radius: 0;border: 0;">
<div class="panel-body">
<h3 id="title" style="text-transform: uppercase; font-weight: bold; text-decoration: underline; margin-bottom: 25px" class="text-center">Dinding 1</h3>
<form>
<div class="row text-left">
<div class="col-md-10 col-md-offset-1">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label style="font-style: italic; font-weight: normal; font-size: 20px">Tinggi</label>
<input type="text" id="tinggi1" name="tinggi" class="form-control new-input tinggi">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label style="font-style: italic; font-weight: normal; font-size: 20px">Lebar</label>
<input type="text" id="lebar1" name="lebar" class="form-control new-input">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label style="font-style: italic; font-weight: normal; font-size: 20px">Pilih Warna</label>
<div class="row">
<div class="col-md-12">
<div class="col-md-4" style="background-color: #fff;padding-top: 15px;padding-bottom: 12px;">
<div id="color-group1">
<input type="radio" name="color" id="color1" class="input-hidden" value="blue" data-name="Hello" style="visibility:hidden; display: none;" />
<label for="color1" style="display: block;">
<span style="width: 100%; background-color: blue; display: block;text-align: center;padding: 50px 0;">
<h4>Warna 1</h4>
</span>
</label>
</div>
</div>
<div class="col-md-4" style="background-color: #fff;padding-top: 15px;padding-bottom: 12px;">
<div id="color-group2">
<input type="radio" name="color" id="color2" class="input-hidden" value="lightblue" style="visibility:hidden; display: none;" />
<label for="color2" style="display: block;">
<span style="width: 100%; background-color: lightblue; display: block;text-align: center;padding: 50px 0;">
<h4>Warna 2</h4>
</span>
</label>
</div>
</div>
<div class="col-md-4" style="background-color: #fff;padding-top: 15px;padding-bottom: 12px;">
<div id="color-group3">
<input type="radio" name="color" id="color3" class="input-hidden" value="brown" style="visibility:hidden; display: none;" />
<label for="color3" style="display: block;">
<span style="width: 100%; background-color: brown; display: block;text-align: center;padding: 50px 0;">
<h4>Warna 3</h4>
</span>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="panel-footer quite-white-tip bg-pink text-white" style="display: none">
<h3 style="text-transform: uppercase; text-decoration: underline; font-weight: 600">Kebutuhan Cat Anda</h3><br>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="media">
<div class="row">
<div class="col-md-5">
<div class="media-left media-middle">
<a href="#">
<img class="media-object img-responsive" src="http://www.catster.com/wp-content/uploads/2017/08/A-fluffy-cat-looking-funny-surprised-or-concerned.jpg" alt="...">
</a>
</div>
</div>
<div class="col-md-7">
<div class="media-body text-left">
<div id="color" style="display: block; clear: both; width: 100%;"></div><br>
<div id="luas"></div>
<div id="hasil"></div>
<div id="title-temp" style="display: none;">Warna</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<button type="button" id="tambah" class="btn btn-sm btn-link">Add</button><br>
<button type="button" id="hitung" class="btn btn-lg btn-success">COUNT</button>
<br><br>
I want to change background of div when i hover my link. How can i achieve this? Currently my code looks like this, but it is not working:
<div class="row">
<div class="col-md-12" style="margin-left: 40px; margin-top: 5px;">
<a id="test" href="">
<div id="test1" class="col-xs-2 button-left">
<img class="button-img" src="{{ asset('/img') }}"></img>
</div>
<div class="col-xs-5 button-right">
<h3 style="margin-top: 10px; text-align: center;">#lang('main.data')</h3>
</div>
</a>
</div>
#test:hover ~ #test1 {
display: none;
}
#test:hover>#test1 {
background: red;
}
<div class="row">
<div class="col-md-12" style="margin-left: 40px; margin-top: 5px;">
<a id="test" href="">
<div id="test1" class="col-xs-2 button-left">
<img class="button-img" src="{{ asset('/img') }}"></img>
</div>
<div class="col-xs-5 button-right">
<h3 style="margin-top: 10px; text-align: center;">#lang('main.data')</h3>
</div>
</a>
</div>
</div>
Here is the full code and it has js, css and html. I got this from an online snippet and I am not good with Javascript. Please help!!!
I have this posed on my home page and taking up the space, would be great to have it all collapsed.
$(document).on('click', '.panel-heading span.clickable', function(e) {
var $this = $(this);
if (!$this.hasClass('panel-collapsed')) {
$this.closest('.panel').find('.panel-body').slideUp();
$this.addClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
} else {
$this.closest('.panel').find('.panel-body').slideDown();
$this.removeClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
}
})
.row {
margin-top: 40px;
padding: 0 10px;
}
.clickable {
cursor: pointer;
}
.panel-heading span {
margin-top: -20px;
font-size: 15px;
}
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Panel 1</h3>
<span class="pull-right clickable"><i class="glyphicon glyphicon-chevron-up"></i></span>
</div>
<div class="panel-body">Panel content</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Panel 2</h3>
<span class="pull-right clickable"><i class="glyphicon glyphicon-chevron-up"></i></span>
</div>
<div class="panel-body">Panel content</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Panel 3</h3>
<span class="pull-right clickable"><i class="glyphicon glyphicon-chevron-up"></i></span>
</div>
<div class="panel-body">Panel content</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title">Panel 4</h3>
<span class="pull-right clickable"><i class="glyphicon glyphicon-chevron-up"></i></span>
</div>
<div class="panel-body">Panel content</div>
</div>
</div>
</div>
</div>
Add this in your css: .closeThisPanel{ display:none; }
Add the closeThisPanel class to the panel-body div.
Add the panel-collapsed class the the clickable span.
Change the icon from glyphicon glyphicon-chevron-up to glyphicon glyphicon-chevron-down
$(document).on('click', '.panel-heading span.clickable', function(e) {
var $this = $(this);
if (!$this.hasClass('panel-collapsed')) {
$this.closest('.panel').find('.panel-body').slideUp();
$this.addClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
} else {
$this.closest('.panel').find('.panel-body').slideDown();
$this.removeClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
}
})
.row {
margin-top: 40px;
padding: 0 10px;
}
.clickable {
cursor: pointer;
}
.panel-heading span {
margin-top: -20px;
font-size: 15px;
}
.closeThisPanel{
display:none;
}
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Panel 2</h3>
<span class="pull-right clickable panel-collapsed"><i class="glyphicon glyphicon-chevron-down"></i></span>
</div>
<div class="panel-body closeThisPanel">Panel content</div>
</div>
</div>
</div>
</div>
I have the following table, I want to choose an option and toggle the color between them. but can not repeat (only one option should be in green...) I've tried everything... =/
$(".roundedOpt").click(function(){
var opt = $(this);
$(opt).attr("style","background:#4AA14A;");
});
http://jsfiddle.net/HVw7E/326/
To toggle one in each list, do
$(".roundedOpt").on('click', function () {
var opts = $(this).closest('td').find('.roundedOpt');
opts.not(this).css('background', '#337AB7');
$(this).css('background', '#4AA14A');
});
FIDDLE
You don't need a variable for this, just use this. :) And I just reset all your blue items to blue first, then set the this clicked item to green. I upudated your js fiddle with this:
$(".roundedOpt").click(function()
{
$(".roundedOpt").removeAttr("style");
$(this).attr("style","background:#4AA14A;");
});
table {
border: 1px solid #000;
}
.roundedOpt {
border-radius: 50%;
width: 16px;
height: 16px;
background: #337AB7;
color: white;
text-align: center;
position:relative;
z-index:1;
font-size: 11.5px;
font-weight: bold;
cursor: pointer;
}
div.dleft {
position: absolute;
}
div.dright{
width:auto;
padding-left:24px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<table>
<tr id="trDetail1">
<td style="vertical-align: middle;">
<span>Options list #1</span>
</td>
<td class="text-justify" style="">
<div style="float:right;padding-left:5px;">
</div><p>Select an option below:</p>
<div style="padding-top:5px;">
<div class="cont">
<div class="dleft">
<div class="roundedOpt">A</div>
</div>
<div class="dright">Option A.</div>
</div>
<div class="cont">
<div class="dleft">
<div class="roundedOpt">B</div>
</div>
<div class="dright">Option B.</div>
</div>
<div class="cont">
<div class="dleft">
<div class="roundedOpt">C</div>
</div>
<div class="dright">Option C.</div>
</div>
<div class="cont">
<div class="dleft">
<div class="roundedOpt">D</div>
</div>
<div class="dright">Option D.</div>
</div>
<div class="cont">
<div class="dleft">
<div class="roundedOpt">E</div>
</div>
<div class="dright">Option E.</div>
</div>
</div>
</td>
</tr>
<br/>
<tr id="trDetail2">
<td style="vertical-align: middle;">
<span>Options list #2</span>
</td>
<td class="text-justify" style="">
<div style="float:right;padding-left:5px;">
</div><p>Select an option below:</p>
<div style="padding-top:5px;">
<div class="cont">
<div class="dleft">
<div class="roundedOpt">A</div>
</div>
<div class="dright">Option A.</div>
</div>
<div class="cont">
<div class="dleft">
<div class="roundedOpt">B</div>
</div>
<div class="dright">Option B.</div>
</div>
<div class="cont">
<div class="dleft">
<div class="roundedOpt">C</div>
</div>
<div class="dright">Option C.</div>
</div>
<div class="cont">
<div class="dleft">
<div class="roundedOpt">D</div>
</div>
<div class="dright">Option D.</div>
</div>
<div class="cont">
<div class="dleft">
<div class="roundedOpt">E</div>
</div>
<div class="dright">Option E.</div>
</div>
</div>
</td>
</tr>
</table>
Just take off your style on click
$(".roundedOpt").click(function(){
$(".roundedOpt").attr("style","");
var opt = $(this);
$(opt).attr("style","background:#4AA14A;");
});
Look at this Fiddle
I am developing and app Using Telerik using Cordova and Kendo UI.
I am having the problem that if I scroll down in a div an then switched to div using a simple display:none on the current scrolled div and a display:block to the new div I want to see that the whole app stays scrolled down and I am having no option for scrolling up I have just got a empty screen.
Here the code I am using:
<body onload="onDeviceReady();logint();">
<div id="tabstrip-home"
data-role="view"
data-title="Login"
data-model="app.loginService.viewModel">
<div id="startupForm" data-role="view" style="display:block;">
<img id="startup" class="startup" src="styles/images/startup.jpg"/>
<input id="closeStartButton" onclick="closeStart();" type="image" src="styles/images/vor.png" name="image" width="40" height="40" style="bottom:0;position:fixed;right:0;">
</div>
<div class="logo-image" id="top" name="top"></div>
<div id="home" data-role="scroller" style="display:none;">
<div id="homeOverview" style="background-color: rgba(255,255,255,0.5);margin-left: 5px;margin-right: 5px;color:black;box-shadow: 3px 3px 20px black;">
<h3 style="padding-top:5px;">Angemeldet als: <span id="user"></span></h3>
<div id="statsNr" style="display:none;">
<h3 >Zählwerke gesamt: <span id="zaehler"></span></h3>
<h3 style="padding-bottom:5px;">Zählwerke erfasst: <span id="zaehlererfasst"></span></h3>
</div>
</div>
<div id="auftragGeladenUndDa">
<div style="margin-left:10px;">
<button data-role="button" data-bind="click: showTermine" style="height: 50px;width: 30%; padding-top: 0.75em; text-align: center;">
Termine
</button>
<button data-role="button" data-bind="click: schhin" style="height: 50px;width: 30%; padding-top: 0.75em; text-align: center;">
Schlüsselliste
</button>
<button data-role="button" data-bind="click: showStats" style="height: 50px;width: 30%; padding-top: 0.75em; text-align: center;">
Statistik
</button>
<button data-role="button" onclick="test();" data-bind="click: showAbles" style="height: 50px;width: 61%; padding-top: 0.75em; text-align: center;">
Erfassen
</button>
<button id="homeErfass" data-bind="click: showUpload" data-role="button" style="height: 50px;width: 30%; padding-top: 0.75em; text-align: center;">
Ergebnisse übermitteln
</button>
</div>
</div>
<div id="auftragNichtDa">
<button id="auftrag" onclick="kAuftragLaden();" data-bind="click: geladen" data-role="button" style="width: 90%; margin: 1em; padding-top: 0.75em;padding-right: 1.5em;padding-bottom: 0.8125em;padding-left: 1.5em; text-align: center;">
Neuen Auftrag laden
</button>
</div>
</div>
<div id="hinweiseForm" style="display:none;">
<h3 id="row" style="color:black;">Hinweis und Schlüsselliste</h3>
<table id="hinweis" border="0" style="z-index: 1;background-color:white;margin-left: 10px;margin-right: 10px;margin-bottom:5%;">
<tr>
</tr>
</table>
</div>
<div id="terminForm" data-role="view" style="display:none;">
<h3 id="row" style="color:black;">Termine</h3>
<div style="background-color: rgba(255,255,255,0.5);margin-left: 5px;margin-right: 5px;color:black;box-shadow: 3px 3px 20px black;">
<p>Keine Termine vorhanden</p>
</div>
</div>
<div id="uploadForm" data-role="view" style="display:none;">
<h3 id="row" style="color:black;">Ergebnisse übermitteln</h3>
<div id="uploadEinheit" style="background-color: rgba(255,255,255,0.5);padding-top:5px;padding-bottom:3px;margin-bottom:3px;margin-left: 5px;margin-right: 5px;color:black;box-shadow: 3px 3px 20px black;">
<input id="theCheckbox" type="checkbox">
</div>
</div>
<div id="statsForm" style="display:none;" >
<div style="background-color: rgba(255,255,255,0.5);margin-left: 5px;margin-right: 5px;color:black;box-shadow: 3px 3px 20px black;">
<h3 id="row" style="padding-top:5px;">Statistik</h3>
<h3 >Zählwerke gesamt: <span id="zaehlerin"></span></h3>
<h3 style="padding-bottom:5px;">Zählwerke erfasst: <span id="zaehlererfasstin"></span></h3>
</div>
<div style="background-color: rgba(255,255,255,0.5);margin-left: 5px;margin-right: 5px;color:black;box-shadow: 3px 3px 20px black;padding-top: 10px;">
<ul data-role="listview" data-style="inset" >
<li><div style="color:black;">Ort:</div>
<label>
<select style="color:black;" onchange="onchangeOrt();" id="statOrt"></select>
</label>
</li>
</ul>
<ul data-role="listview" data-style="inset" >
<li>
<div style="color:black;">Strasse</div>
<label>
<select style="color:black;" onchange="onchangeStrasse();" id="statOrt"></select>
</label>
</li>
</ul>
</div>
<div id="savedStrasse"></div>
</div>
<div id="ablesForm" style="display:none;" >
<ul data-role="listview" data-style="inset">
<h3 id="row" style="color:black;margin-bottom: 0;margin-top: 0;">Orte</h3>
<li>
<input id="stift" type="image" src="styles/images/erfassen.png" name="image" width="40" height="40" style="">
<input type="image" src="styles/images/suchen.png" name="image" width="40" height="40" style="">
<input type="image" src="styles/images/foto.png" name="image" width="40" height="40" style="">
<input type="image" src="styles/images/karte.png" name="image" width="40" height="40" style="">
</li>
<li>
<select id="recog" onchange="changeFunc();" style="color:black;left: 0;width: 200px;"> </select>
<select id="2tab" onchange="changeAnz2();" style="margin-right:60px;color:black"><option value="1">K</option><option value="2">Z</option></select>
<select id="alleOffen" onchange="changeAnz2();" style="color:black;"><option value="1">Alle</option><option value="2">Offen</option></select>
</li>
</ul>
<div id="all1" style="font-size: 18pt;height:95%;background-color:white;margin-top: 0;margin-left:25px;margin-right:25px;box-shadow: 3px 3px 20px black;"></div>
<div id="all2" style="font-size: 18pt;height:95%;display:none;"></div>
<div id="all3" style="font-size: 18pt;height:95%;display:none;"></div>
<div id="all4" style="font-size: 18pt;height:95%;display:none;"></div>
</div>
<div id="erfassForm" style="display:none;" >
<div style="background-color: rgba(255,255,255,0.5);margin-left: 5px;margin-right: 5px;color:black;box-shadow: 3px 3px 20px black;padding-top: 1px;">
<h3 style="color:black;display:none;" id="erfassName"></h3>
<h3 style="color:black;" id="erfassNameAnz"></h3>
<h3 style="color:black;display:none;"id="zaehlerNr"></h3>
<h3 style="color:black;"id="adresse"></h3>
<h3 style="color:black;display:none;"id="erfassStrasse"></h3>
<h3 style="color:black;display:none;"id="erfassHausnr"></h3>
<h3 style="color:black;display:none;"id="zpunktID"></h3>
<h3 style="color:black;display:none;"id="zaehlerID"></h3>
<h3 style="color:black;display:none;" id="ablEin"></h3>
<h3 style="color:black;display:none;" id="gerNR"></h3>
<h3 style="color:black;display:none;" id="AbleserNR"></h3>
<h3 style="color:black;"id="standMin" ></h3>
<h3 style="color:black;"id="standMax" ></h3>
<h3 style="color:black;display:none;" id="plasib"></h3>
<h3 style="color:black;display:none;" id="rebuild"></h3>
<select id="alleOrte" style="color:black;width: 45%;"></select>
<select id="alleAbleser" style="color:black;width: 45%; margin-left:20px;"></select>
<h3 style="color:black;margin-bottom: 0;">Zustandsmeldung</h3>
<select id="alleFehler" style="color:black;"></select>
<h3 style="color:black;margin-bottom: 0;">Aktueller Zählerstand</h3>
<input id="stand" type="stand" style="margin-left: 10px;"/>
<button data-click="reset" onclick="erfassenZae();" data-role="button" style="width: 40%; margin: 1em; padding-top: 0.75em;padding-right: 1.5em;padding-bottom: 0.8125em;padding-left: 1.5em; text-align: center;">
Erfassen
</button>
</div>
<br><br><br><br><br><br>
<div class="result-area ch50">
<div class="results">
<img style="display:none;margin:5px auto; width:120px; height:120px;" id="smallImage"/>
</div>
<div class="separator"></div>
</div>
</div>
<div id="settings" style="display:none;" >
<div id="adminMS" style="color:black;display:none;">Kennwort
<input id="adminPass" style="text-align:right;width: 150px;color: black;"/>
</div>
<div id="server" style="color:black;">
<p>Sie müssen beim ersten Start einen Server einrichten. Bitte machen Sie dies jetzt!</p>
<p id="infofield"></p>
<p id="os"></p>
<p id="version">2.0.0.6</p>
<div style="display:inline">
<p>Serveradresse:</p>
<input type="text" id="eingabe" style="width: 80%; margin-left: 5px;"/><br>
<button onclick="serverSpeichern();" id="serverTres" data-role="button" style="width: 40%; margin: 1em; padding-top: 0.75em;padding-right: 1.5em;padding-bottom: 0.8125em;padding-left: 1.5em; text-align: center;">Speichern</button>
</div>
<p>Qualitätsstufe (in Prozent) <input type="text" id="qalID" style="width: 100px; margin-left: 5px;"/><br></p>
<button id="settingsCloseButton" onclick="closet();logint();qalSpeichern();" data-role="button" style="width: 40%; margin: 1em; padding-top: 0.75em;padding-right: 1.5em;padding-bottom: 0.8125em;padding-left: 1.5em; text-align: center;">Ok</button>
</div>
<button id="adminButton" onclick="showServer();" data-role="button" style="display:none;width: 40%; margin: 1em; padding-top: 0.75em;padding-right: 1.5em;padding-bottom: 0.8125em;padding-left: 1.5em; text-align: center;">Anmelden</button>
</div>
<form data-bind="events: { keyup: checkEnter }" id="logForm" style="background-color: white; padding-top: 1px;margin-left: 10px;margin-right: 10px;height:95%;box-shadow: 3px 3px black;">
<h3 data-bind="invisible: isLoggedIn" style="color:black;font-size:16pt;">Benutzeranmeldung</h3>
<ul data-role="listview" data-style="inset">
<li>
<div style="color:black;margin-left:5px;">Geräte gesamt:
<div style="width: 30%;border: 1px solid gray;height: 20px;display: inline-block;float: right;border-radius: 5px;background-color: white;"></div>
</div>
<label>
</label>
</li>
<li style="top:0;margin-left:5px;">
<div style="color:black;">Geräte abgelesen:
<div style="width: 30%;border: 1px solid gray;height: 20px;display: inline-block;float: right;border-radius: 5px;background-color: white;"></div>
</div>
<label>
</label>
</li>
<li><div style="color:black;margin-left:5px;height: 40px;">Ableser</div>
<label>
<select style="width: 30%;border: 1px solid gray;display: inline-block;float: right;border-radius: 5px;background-color: white;color:black;margin-right: 10px;" onchange="onchangeLogin();" id="Model" type="number" data-bind="value: username"> </select>
</label>
</li>
<li>
<div style="color:black;margin-left:5px;margin-top: 5px;">Kennwort</div>
<label>
<input id="passInput" onkeyup="disableButton();" onclick="cleart();" style="text-align:right;width: 30%;border: 1px solid gray;height: 20px;display: inline-block;float: right;border-radius: 5px;background-color: white;color:black;margin-right: 10px;" type="password" data-bind="value: password"/>
</label>
</li><br>
<li><button id="login" type="submit" data-role="button" data-bind="click: onLogin" value="Login" class="login-button" style="-webkit-border-radius: 5px;background-color: rgba(200,200,200,1.0);box-shadow: 3px 3px black;color:black;float:right;width:30%;">weiter</button></li>
</ul>
<!--<button onclick="settings();serverAnzeigen();" data-role="button" style="width: 40%; margin: 1em; padding-top: 0.75em;padding-right: 1.5em;padding-bottom: 0.8125em;padding-left: 1.5em; text-align: center;">Einstellungen</button>
--><br>
</form>
</div>
<input onclick="openStart();" type="image" src="styles/images/zurueck.png" style="display:none;"name="image" width="40" height="40">
<div data-role="layout" data-id="tabstrip-layout">
<div data-role="header">
<div data-role="navbar">
<span data-role="view-title"></span>
</div>
</div>
<div data-role="footer" >
<div id="footert" style="width: 100%;display:none;">
<input id="closeButton" onclick="showHome();" type="image" src="styles/images/zurueck.png" name="image" width="40" height="40" style="bottom:0;position:fixed;">
<input id="closeHome" onclick="logout();" type="image" src="styles/images/zurueck.png" name="image" width="40" height="40" style="bottom:0;position:fixed;">
<input id="uploadButton" onclick="uploadAll();" type="image" src="styles/images/uebermitteln.png" name="image" width="40" height="40" style="bottom:0;position:fixed;display:none;">
<!--<button id="closeButton" onclick="showHome();" data-click="reset" data-role="button" style="width: 40%; text-align: center;display:none;">Schließen</button>
<button id="erfassButton" data-click="reset" data-bind="click: showErfass" data-role="button" style="display:none; width: 40%; text-align: center;">Ablesen</button>
-->
<input id="settingsButton" onclick="settingsH();" type="image" src="styles/images/einstellungen.png" name="image" width="40" height="40" style="bottom:0;position:fixed;display:none;">
</div>
</div>
</div>
</body>
</html>
No I am for exmaple scrolling down in the div named hinweiseForm and then going back using the following function:
function showHome(){
document.getElementById("ablesForm").setAttribute("style","display:none;");
document.getElementById("hinweiseForm").setAttribute("style","display:none;");
document.getElementById("statsForm").setAttribute("style","display:none;");
document.getElementById("home").setAttribute("style","display:block;");
document.getElementById("erfassForm").setAttribute("style","display:none;");
document.getElementById("uploadForm").setAttribute("style","display:none;");
document.getElementById("terminForm").setAttribute("style","display:none;");
document.getElementById("closeHome").setAttribute("style","display:block;"); document.getElementById("footert").setAttribute("style","position:fixed;bottom:0px;width: 100%;display:block;");
document.getElementById("plasib").innerHTML="";
document.getElementById("closeButton").setAttribute("style","display:none;bottom:0;postion:fixed;");
document.getElementById("uploadButton").setAttribute("style","display:none;");
document.getElementById("settingsButton").setAttribute("style","display:block;bottom:0;margin-left:50px;position:fixed;");
document.getElementById("settings").setAttribute("style","display:none");
//$("#home").data("kendoMobileScroller").reset();
//new kendo.mobile.Application();
//app.application = new kendo.mobile.Application(document.body, { layout: "tabstrip-layout" });
}
I already tried some things like the reset function but either I am not using it right or I need to do it another way. It would be really awesome if you can help me.
Thanks in advance
I use the scrollTo method to scroll to the top of my views.
app.application = new kendo.mobile.Application(document.body, {
layout: "tabstrip-layout"
});
// get the view scroller
var scroller = app.application.view().scroller;
/*
* scroller.scrollTop = The number of pixels that are hidden from view above the
* scrollable area.
*/
if (scroller.scrollTop) {
scroller.scrollTo(0, 0);
}