How to remove Inline CSS using JS? - javascript

I have
<div class="slide slick-slide slick-current slick-active" data-slick-index="0"
aria-hidden="false" style="width: 1730px; position: relative; left: 0px; top:
0px; z-index: 999; opacity: 1;" tabindex="0" role="tabpanel" id="slick-slide00" aria-describedby="slick-slide-control00">
I want to remove z-index, I tried
jQuery(document).ready(function( $ ){
jQuery('.slick-slide).css('z-index', "");
});
and
jQuery(document).ready(function( $ ){
jQuery('.slick-slide).css('z-index', "auto");
});
and I tried all the classes listed in the div above, nothing worked. I just want to remove the z-index, it's a wordpress site, so using JS/JQuery are my only options.

You don't need jQuery - use Element.style.removeProperty():
document.querySelector(".slick-slide").style.removeProperty("z-index");

As requested per comments above:
Simply override .slick-slide in your CSS with !important, no JavaScript required.
.slick-slide {
z-index: 0 !important;
}
Edit:
0 is simply a placeholder, choose a value you see fit or set to initial for the default value of z-index.

If you only have z-index as inline and want to remove it you should remove the whole style attribute instead.
`$('.slick-slide').removeAttr('style');`
I see that you are using Slick Slider. I recommend not to delete any styles served by Slick. Better to write an ugly override with some CSS instead.

I'm adding my own answer but cannot accept it since I'm not sure it's the right answer.
The better solution is to set the parent div that you created
.example-banner {
z-index: 0;
}
And leave slick slider as is, that would fix the issue too. The difference is that if you do like the accepted answer suggested, like I suggested previously, you'll face an issue which is that if you click on any href, it will take you to the last href of the slider.
So lets say your slider has 5 slides and each slide has a link to an article, when you click on any of those links, you'd be taken to the last article.

Related

How to make overflow-y scroll without changing overflow-x to auto?

I know this is a duplicated question.
And below link is the answer the most nearest with my question that I've found.
CSS overflow-x: visible; and overflow-y: hidden; causing scrollbar issue
In this link, the W3C spec says:
The computed values of ‘overflow-x’ and ‘overflow-y’ are the same as
their specified values, except that some combinations with ‘visible’
are not possible: if one is specified as ‘visible’ and the other is
‘scroll’ or ‘auto’, then ‘visible’ is set to ‘auto’. The computed
value of ‘overflow’ is equal to the computed value of ‘overflow-x’ if
‘overflow-y’ is the same; otherwise it is the pair of computed values
of ‘overflow-x’ and ‘overflow-y’.
What I want to know is, are there any new solution of this.
The problem of mine is in this fiddle.
I made 'sidebar' class of 'BootStrap' simple in a fiddle of mine.
overflow-x: visible;
//overflow-y: scroll;
You can see that I commented out 'overflow-y: scroll' of class '.panel' in css part.
In this case, 'hover' will work but 'scroll' won't.
When if I clear that comment out, 'hover' won't work but 'scroll' will.
What I wanna see is, 'hover' and 'scroll' working together.
Does anyone have any ways or ideas to fix this?
Or are there still no way to solve this problem?
Your code is working you just can't see hover because of the width you set to that block is 50px also if you set position:absolute in hover you can see that hover effect but it overlap the child item. so one thing i want to know you want same width or you just set for a demo purpose.
You could use jQuery so you will change the .panel overflow depending on the event.
Absolutely you will need a little of css hacks also,
See the updated JSfiddle.
I liked this question.
So, I have created a fiddle here: https://jsfiddle.net/n4tvvora/4/
Its comes pretty close to what you need (I think). Let me know if it does NOT suit your requirement. We can make it better.
Code highlights:
.panel:hover ul.list:first-child {
position: absolute;
display: inline-block;
height: 100%;
width: auto;
overflow-y: auto;
overflow-x: hidden;
}
.panel ul.list:first-child {
display: block;
}
I've solved this by adding 'div' between 'div' and 'ul'.
And here's my final fiddle which works almost fitting with my intent.
<div class="panel"> // added div
I hope this working will be helpful for anybody. :)

How to add a class to parent element when there are several

as described in the title I would like to add a class to the parent element of one element if I have several of the parents.
To explain it in more detail what I mean, I'll give you a quick overview of the initial situation.
The markup:
<div class="box">
<h3>Title</h3>
<p>Some text</p>
<span class="iconfont more"></span>
<div class="slide">
<p>some more text</p>
<span class="iconfont close"></span>
</div>
</div>
As you see I've created a div "box" with some content, a span and also another div "slide" with some content and a span too.
The CSS:
.box {
width: 300px;
height: 500px;
position: relative;
}
.slide {
width: 300px;
height: 500px;
position: absolute;
top: -500px;
left: 0;
transition: all 500 ease-in-out
}
Let's add a bit of styling. The divs now have a width, height and position plus the slide box has received a transition to make the hole thing smooth. You may already know where the journey will end.
So let's do it by bringing up a new player:
.box.slided .slide {
top: 0;
}
For now the rest is pure routine. Add/remove the class .slided to .box by clicking the span. It works fantastic and everyone is happy except me. Because what if I have more of these boxes? Of course using IDs instead of classes to make them unique will solve this too. But what if I don't know how many of them I'll have? And that's exactly the point.
How can I add or remove the class .slided to exact this div.box that contains the span I'm clicking on?
Thanks for your help
Edit: code I've tried
$('div span').stop().click(function(event) {
$('box').addClass('slided');
});
Use $(this) and closest() to traverse the DOM in a relative fashion:
$('.more').click(function () {
$(this).closest('.box').toggleClass('slid');
});
Demo
Note that I've added a negative z-index to your slider div to prevent it from covering the 'more' link, rendering it inaccessible. This is probably not a viable production solution.
Here's an updated version with the transition working properly.
You can find your closest parent that matches your selector like this:
$('div span').stop().click(function(event) {
$(this).closest('.box').addClass('slided');
});
This code will now find its box parent in the context of the span that was clicked.

jQuery - slide down panel

I want to create a website where the user has to enter soma data. To make this as easy as possibble, i just show the main input elements and let a helper panel slide down if needed. As possible, these panels should be draggable (i am looking for javascript for that in the moment). My main problem is that when the panel slides down, the content at the top is shown first, but i want to slide down like shown below:
Is there any way to make this?
Thanks in advance.
Look at this JSFiddle.
This should show the principle to achieve this effect. You need a container div with overflow: hidden; and a child positioned to the bottom of the container div, then you can change the height of the container with jQuery to show/hide the content.
Also, to make the panels draggable, jQuery UI has a great function called draggable which works great. Give it a try.
Quick access: Fiddle: http://jsfiddle.net/VuPyL/1/ (updated) , BTW: I made it toggle-like.
Generally it seems to be only solve-able with animate,
if you dont want to have any wrapper element you would really like to use DOM's native property "scrollHeight" - that allows you to scroll always to bottom, in combination with a height toggle, it does exactly what you need.
Overflow: hidden dont have to be in the CSS - jQuery is adding it itself while toggling height.
This solution may seem a bit longer, but is more clear in what is actually happening :) :
HTML
<div id="helper-panel">
Here's
<br />
My
<br />
Content
</div>
<button id="show-helper">Show/hide Helper Panel</button>
CSS
#helper-panel{
height: 70px;
width: 375px;
position: relative;
overflow: hidden; /*optional - jQuery is adding it*/
display: none;
}
JS/jQuery
$('#show-helper').click(function(){
var $helper = $('#helper-panel');
$helper.animate({
height: "toggle"
},{
duration: 800,
progress: function(){
$helper.scrollTop( $helper[0].scrollHeight );
}
});
});
As suggested by #Andrew Pope to have item draggable/droppable it is best to use jQuery UI's draggables&droppables.
Also check sortable if you just want to change the order of the helper-menu items using drag&drop ;)
jQuery UI is not a standard part of jQuery - so dont forget to include it.
When using these it is good to wrap each draggable element. So the HTML would be:
<div id="helper-panel">
<div>Here's</div>
<div>My</div>
<div>Content</div>
</div>
And the jQuery (with jQuery UI):
$('#helper-panel').sortable() //make the items inside #helper-panel sortable
.disableSelection() //when sorting, you dont want selecting
.css('cursor','default'); //looks better with default cursor

JQuery autocomplete appears behind JQuery menu

I have a JQuery autocomplete search box which when displaying the search results in the dropdown window appears behind a JQuery dropdown menu directly below it (see image). I have tried increasing the z-index value of everything I can find in the CSS for the autocomplete search but it still doesn't fix the problem. What else should I be trying?
Fiddle link: http://jsfiddle.net/tonyyeb/LKDBh/18/
Thanks for everyone's contributions. I have since found a solution given to me by a forum user:
The autocomplete wrapper is being given a z-index of 1 by the jQuery library (hard-coded), >whereas the menu (via CSS) has a z-index of 100; easiest solution is to use -
.ui-autocomplete {
z-index: 100 !important;
}
I had a similar issue with a website recently and I've fixed this with the following method:
Make sure that you position both elements absolute OR relative (z-index only works when you use the 'position' css element. So you should either use position: absolute; or postion: relative;. That totally depends on your code/css. When you don't use the position element right now, you should probably use the position: relative; element since the position:absolute; element will position the referring element absolutely which will probably screw up your layout).
Then make sure you give the dropdown a z-index which is lower then the z-index for the menu.
Example
.search-dropdown{
position: relative; or position: absolute;
z-index: 1;
}
.jquery-menu{
position: relative; or position: absolute;
z-index: 2;
}
Now, you've added
position: relative;
z-index: 1;
to .ui-widget.
Remove it there and add it directly to the dropdown's css which appears when you enter something in the input field (Chrome/Firefox: Right Click on the dropdown and inspect element to see its class/ID).
Hope this helps!
A few months ago I had a similar problem, and searched the web.
The solution was in the CSS styling.
I added an inline class (ui-front) to the element that holds the autocomplete input element.
Not sure it will solve your problem, but it's an easy experiment.
Best of luck!
Question has been posted long time ago. Still, i also have a solution that works and not listed till now .
just add this on top of your page and problem should be solved.
.pac-container { position: absolute; cursor: default;z-index:3000 !important;}

changing element.style on the finishing position of a jQuery animated div

I am using a photo album jQuery plugin (Supersized). It includes a thumbnail tray which slides up from the bottom of the screen at the touch of a button, resulting in the following HTML being created onto the div properties and in firebug css 'element.style. property:
style="display: block; bottom: -150px;"
and when caller clicked:
style="display: block; bottom: 0px;"
I am trying to place a footer div at the bottom of the page though, so want to move the finishing position to 'bottom:0px'. I have seen that an extra element.style can be added to local CSS but without a 'before' and 'after' type of selection I don't understand if that can help me. Furthermore I don't find the function in the JS files and from what I understand it can't be accessed anyway. I need to change these to be:
style="display: block; bottom: -150px;"
and when caller clicked:
style="display: block; bottom: 42px;"
Any advice would be most welcome. Thanks
$('#clickedElement').on('click', function() {
$('#element').css('bottom', '42px')
});
If i didn't missunderstand you?
Probably the function which you can not find is jquery .css() function you can read how it works here.
Also if you want to animate some dive you can use jquery .animate() function (docs).
In your case it should looks like:
$('#button').click(function() {
$('#element').animate({
$('#element').css('bottom', '42px');
}, 5000, function() {
});
});
Where 5000 it's time of your animation in miliseconds.

Categories

Resources