Change the divs style in parent of parent using jquery [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to change the div's style which is located in the parent of a parent. I am able to access them via DOM, but how can I change its CSS style using JQuery?
Selection code:
window.parent.parent.parent.document.getElementsByTagName('code').
I would love to only change a div that doesn't have display:none already set, but I really don't care if we change only one, or all of them.

You can always use the context parameter on $( selector [, context ] )
$("[name=code]",parent.parent.parent.document).css('display','none');
If you want to only change the one that are visible you can use the is function in JQuery in order to filter:
$("[name=code]",parent.parent.parent.document).is(':visible').css('display','none');
JQuery page: https://api.jquery.com/jquery/

Related

Get the closest iframe to a parent element [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
i am trying t get the closest iframe element to a parent element so can identify the iframe that i want to stylize with css:
<div class ="accroche">
<iframe></iframe>
<iframe></iframe>
<iframe></iframe>
<iframe></iframe>
</div>
What would be the best technique knowing that the iframes are generated by another tool and there is no way to identify them
Well if I understand your problem it’s the first element of the list so you can do something like that in your css to style it :
.accroche iframe:first-child{ … }

Remove div class if display:none [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I would like to know if there is a way to remove a class when that class is marked with display: none;. Basically, I would like to prevent it from loading.
Is it possible to do it using JQuery?
Thanks in advance!
$('.class-you-want-to-remove:hidden').removeClass('class-you-want-to-remove');
https://api.jquery.com/hidden-selector/
You can use hide() method in jQuery to hide the blocks under that class.
$(".classname").hide();
Similarly you use show() method to show the blocks under that class.
$(".classname").show();

Recreate behavior "background-attachment: fixed" with a div [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to recreate this effect that is achieved using the CSS property background-attachment:fixed, but I would recreate that effect using divs, I would recreate that on a h1 tag for example.
Is that possible?
Thanks
you have to customised http://tympanus.net/Blueprints/ScrollingLayout/js/cbpFixedScrollLayout.min.js
to achieve " I would recreate that effect using divs, I would recreate that on a h1 tag for example" instead "section" as it has below code
var cbpFixedScrollLayout=(function(){var a={$sections:$("#cbp-fbscroller > section")...
so it will always create this effect on section element.
so if you want to create it any other tag rather than section then you have yo customise above js, please try to implement it first .

Using CSS in JS [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to change CSS elements depending on situations used in javascript.
an example I had tried was:
if ('image'=="clicked")
{blahblahblah}
'image' would be my div id or div tag in CSS.
I know in Jquery I can use $('#image').click, but I don't think it Jquery will be good for my situation.
Consider document.querySelector. It's powerful, accepting any valid CSS selector. You can even start from another element, such as myElement.querySelector, to only get children of that element that match the selector. Very useful!
Just be aware that IE7 and below do not support this function.
Assuming your id as image
document.getElementById('image').onclick = function() {
alert("button was clicked");
}​;​

Find div with class and add HTML5 data attribute? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to find a div with a specific class or id, then adding a custom HTML5 data attribute to it. For example:
Find:
<div class="mydv">Hello</div>
Then add data-customtype="one" so it becomes
<div class="mydv" data-customtype="one">Hello</div>
However, the following code does not seem to work:
$('.mydv').data('customtype','one');
jQuery's .data() function will not add an HTML5 data tag, the data will be saved to the computer's memory instead. The user will have to use .attr() in order to add a physical attribute to the tag.
This example will work:
$('.mydv').attr('data-customtype','one');
you should use .data() to get/set data attributes:
$('.mydv').data('customtype','one');
Working Fiddle
Do it like this simply.
to set the value:
$('.mydiv').attr('data-customtype','one');
to get the value:
$('.mydiv').attr('data-customtype');

Categories