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");
};
Related
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();
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 6 years ago.
Improve this question
Weave: http://kodeweave.sourceforge.net/editor/#f6d9a54288f17fb68a8b234ec364dc41
I love JQuery, I do, but just for fun I'd like to learn how to write the following in pure/vanilla JS.
$("iframe").contents().find("<style>").html(cssEditor.value))
Something like this should work:
document
.getElementsByTagName('iframe')[0]
.contentDocument
.getElementsByTagName('style')[0]
.innerHTML = cssEditor.value;
Use the contentDocument property of the <iframe> DOM object to get the inner document.
You can then call normal methods on it like querySelector.
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
Hi I'm trying to invert everything on the page except for images? Any help will be appreciated. Thanks.
http://jsfiddle.net/nikita_turing/jVKw6/3/
Bookmarklet
If you can use jQuery, use the pseudo selector :not(img) to select all the elements except images, then set the CSS you want.
Something like
$(":not(img)").css({"-webkit-filter": "invert(100%)","-moz-filter": "invert(100%)","-o-filter": "invert(100%)","-ms-filter": "invert(100%)"});
There are can be two different solutions. Maybe not the best.
The first, Find all images
Then invert elements and invert images back to the first condition.
The second, using jQuery get all img elements and do the same work as in the previous idea.
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 have a CoffeeScript code that looks like this:
if $('#user_address_attributes_country').val() == ""
$('#user_address_attributes_country').val("PL")
Now I want to do the same thing for a few divs but without repetitions.
How can it be done by jQuery?
The reason you can't apply it multiple times is because your trying to apply it to an element which has an id. They are unique. Use classes and do this instead:
if ($('.user_address_attributes_country').val("")) {
$('.user_address_attributes_country').val("PL");
}
Simple demo: JsFiddle
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/