Good afternoon, do you know if there is any way to hide the 'Dropdown' that appears with the options of a select when clicking on it? When click add a class to an element to show a hidden div but for something less than 1 sec you see the dropdown.
If you can help me, I would be grateful
A greeting.
$('.select').on('click', function(e) {
e.preventDefault();
$(this).attr("disabled", true);
$('.options_select').addClass('show');
});
No, is a replaced element, that is rendered by the operating system. There is no CSS option to hide the drop-down.
There's some notes on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#Styling_with_CSS
I think you can get what you're looking for like this: https://codepen.io/gerard-payne/pen/NVjppd
select {
appearance: textfield;
-webkit-appearance: textfield;
}
option {
display: none;
}
but also setting disabled and adding a font color.
<select disabled="disabled">
<option>2000</option>
<option>2001</option>
<option>2002</option>
</select>
select[disabled="disabled"] {
color: black;
}
don't add the options to the list or add something like:
CSS:
.select > option {
display: none;
}
$(".select").on('click',function(){
$('.submenu').toggle();
})
.select{ border:solid 1px #000; display:inline-block; padding:20px; cursor:pointer;}
.submenu{ background:#345; display:none;}
.submenu a{color:#fff;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="select">Select</div>
<div class="submenu">
option
option
option
option
</div>
i think you want this? if not let me know
Related
I'm working on my portfolio website and need some help with a bit jQuery code. I want a parent class to react to the checkbox in it. In this case, the background color needs to change to #000 when the checkbox is active/checked.
I don't know what line of code to add to make my class react to the checkbox. I've searched on google on how to do it but didn't get much wiser. It's probably a really small thing but I would hope to get some help from you guys.
$("input[type='checkbox']").change(function() {
if ($(this).is(":checked")) {
$(this).parent();
} else {
$(this).parent();
}
});
.product {
background-color: #ccc;
/* needs to change to #000 when active */
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div class="product">
<input class="check" type="checkbox" name="logo"> Logo
</div>
Basically you create a second (more specific) css selector for the active state, then you use your jQuery to toggle that state/class based on the checkbox value.
https://jsbin.com/betafupogu/1/edit?html,css,js,output
CSS
.product {
background-color: #ccc; /* needs to change to #000 when active */
}
.product.active {
background-color: #000;
}
jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$("input[type='checkbox']").change(function(){
if($(this).is(":checked")){
$(this).parent().addClass('active');
}else{
$(this).parent().removeClass('active');
}
});
</script>
I need to add checkbox to Avengers, S.H.I.E.L.D., & Justice League & Superheroes & You Have Selected List
In this below demo code
jsfiddle.net/nzdak7aL/98
Add this into js
$('option').mousedown(function(e) {
e.preventDefault();
$(this).prop('selected', !$(this).prop('selected'));
return false;
});
and into css
option::
before {
content: "\2610";
width: 1.3em;
text-align: center;
display: inline-block;
}
option:checked::before {
content: "\2611";
}
Try this http://jsfiddle.net/nzdak7aL/101/
Your request is unclear. Could you please add more details?
If I understand it correctly, you would like add checkboxes to the multi select field? This does not make any sense.
If you need custom styled checkboxes just do this:
<input id="checkbox-avenger" type="checkbox" name="something" value="Avengers" style="display: none;" />
<label for="checkbox-avenger">**here you custom layout stuff**</label>
When you enter my website (goerann.com) the dropdown register-box is down by default.
If I click in Register, the register-box toogles it visibility as I want, but it doesn't start hidden by default.
$(document).ready(function() {
$('#signup').click(function() {
$('.signupmenu').slideToggle("fast");
});
});
I want it to only show when you click on it. How can I make this happen?
Here's my jsfiddle (http://jsfiddle.net/bdv2doxr/)
Since you're already using the $(document).ready event, you can hide the menu there:
$(document).ready(function() {
$('.signupmenu').hide();
$('#signup').click(function() {
$('.signupmenu').slideToggle("fast");
});
});
And here is your fiddle updated.
You need to make two changes, both involving the removal of display: block. When you toggle this div, it will make the display block. Therefore, you can initialize it as display: none.
Change this:
<div class="signupmenu" style="display: block;">
to this:
<div class="signupmenu">
And also change this:
.signupmenu {
background-color: #FFF;
display: block;
...
to this:
.signupmenu {
background-color: #FFF;
display: none;
...
Updated fiddle here
I am trying to have the classes change depending on what is clicked from the two headings.
If heading one is clicked, I want the font color to change to red and have it underlined with red, which in the class it currently does with a bottom border. If the other heading is clicked then I want that heading to take on the red characteristics. The one that is not clicked will just stay grey according to the no highlight class.
Here is the JSFiddle: http://jsfiddle.net/7ok991am/1/ I give an example look also of what I am trying to accomplish.
HTML:
<div id="page_headings">
<h2 class="no_highlight">Heading One</h2>
<h2 class="no_highlight">Heading Two</h2>
</div>
CSS:
#page_headings{
overflow: hidden;
margin-bottom: 32px;
}
#page_headings h2{
float: left;
margin-right:24px;
font-size: 14px;
cursor:pointer;
}
#page_headings h2:hover{
font-weight: bold;
}
.red_highlight{
color:red;
border-bottom: 1px solid red;
}
.no_highlight{
color:#898989;
}
JS:
$('#page_headings').on('click', function(){
if($('#page_headings h2').hasClass('no_highlight')){
$(this).removeClass('no_highlight').addClass('red_highlight');
}else{
$('#page_headings h2').addClass('no_highlight');
};
});
Building on #RDrazard I think you want them to switch between the two correct?
http://jsfiddle.net/7ok991am/3/
$('#page_headings h2').on('click', function(){
if($(this).hasClass('no_highlight')){
$(this).removeClass('no_highlight').addClass('red_highlight');
}else{
$(this).addClass('no_highlight');
}
$(this).siblings('h2').addClass('no_highlight');
});
JSFiddle: Link
First off, add a border-bottom property with none to the no highlight class to ensure that it looks just the same before the click.
Next, you want to the click event associated with the h2 elements, so it should be $('#page_headings h2')
Use this to impact the h2 we're clicking on.
Try this code
$('#page_headings h2').on('click', function(){
if($(this).hasClass('no_highlight')){
$(this).removeClass('no_highlight').addClass('red_highlight');
}else{
$(this).addClass('no_highlight').removeClass('red_highlight');
}
});
Check this fiddle
JS
$('.no_highlight').on('click', function(){
$(this).parent().find('.no_highlight').css('border-bottom','none');
$(this).css('border-bottom','1px solid red');
});
The above method changes the border of the currently clicked headinh which i think is what you want.
AND
if you want addClass() and removeClass(), then see this fiddle
JS
$('.no_highlight').on('click', function(){
$(this).parent().find('.no_highlight').removeClass('red_highlight');
$(this).addClass('red_highlight');
});
This method adds a red_highlight class to the active link and removes the red_highlight when not active.
Please try it..
I am trying to style a select element that is created in php. The select code is very simple and I can style the text color of the drop down. But this doesn't style the select element when a option is selected. Also this code doesn't work on Safari at all.
Code:
<div class="theme">
<select class="theme" name="select_theme">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
</div>
CSS:
.theme {
width: 200px;
}
.theme select {
width: 200px;
background-color: rgba(200,200,200,0.8);
}
.theme select option[value="red"] {
color: red;
}
.theme select option[value="green"] {
color: green;
}
.theme select option[value="blue"] {
color: blue;
}
How do I style the default select so that it matches the option style rule?
How to get this to work on Safari? Possibly IE I haven't checked it yet no Windows system ATM.
Is there a way to get these rules to display an image as well? I've tried a few things but seems it requires Javascript which I try to avoid when I can.
I made a JSFiddle to demonstrate this.
There's no way you can accomplish this without JavaScript:
$('select.theme').change(function () {
$(this).css('color', $(this).find('option:selected').css('color'));
}).change();
Here's your fiddle: http://jsfiddle.net/uCmSR/2/