query selector all elements that are "display: none;" [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have the following query selector but it does not work. Why?
document.querySelectorAll('div:not[style*="display: none;"]')
I got the following error is not a valid selector
It is working correctly without the :not but doesn't give me what I'm looking for.
so I guess I'm not using the :not correctly

You are forgetting the (), use like this :not([...])
let a = document.querySelectorAll('div:not([style*="display: none;"])')
console.log(a)
<div style="display: none;">a</div>
<div>a</div>
<div style="display: none;">a</div>
<div>a</div>
<div style="display: none;">a</div>
BUT, my suggestion is to use a class that hide the div and then use the query looking for that class... Because this selector: [style*="display: none;] is too fragile, it wont get elements that have, for example: style="display: none" (without ;) or style="display:none;" (without a space)

:not uses parentheses - it's kind of like a function. Try this:
document.querySelectorAll('div:not([style*="display: none;"])')

Related

Why won't my delete button work? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have some background in computer programming, but I am just getting into Javascript and jQuery. I have this code that will delete the element's grandparent but the function isn't running at all ("I am not seeing the "alert".) Can you help me find out what is wrong?
NOTE: There are multiple .trashbuttons and I just want the .trashbutton being clicked's grandparent getting deleted.
$("trashbutton").click(function() {
this.parent().parent().remove();
})
EDIT: The answers I have been given are not working. I should also note that the .trashbutton is a img. If that helps.
You have an error in your selector, you forgot the . to select css classes.
And wrap this to $().
try
$(".trashbutton").click(function() {
$(this).parent().parent().remove();
})
I suggests you to keep reading on jQuery and javascript, especially this documentation about jquery selector. Your script function properly, except that $("trashbutton") refer to a <trashbutton></trashbutton> tag, that doesnt exist in your code ( i guess ). If you wanted to target an element class with that use $(".trashbutton") or $("#trashbutton") to target an element with this ID :)
Use $(this)...this will represent DOM element but you need jQuery wrapped element.
Try this:
$(".trashbutton").click(function() {
$(this).parent().parent().remove();
})
Edit: As suggested in comments, make sure you have $("trashbutton") as valid selector..I assume you are dealing with classes hence it should be $(".trashbutton")
You should use #trashbutton if it is an id or .trashbutton if it is a class. Also wrap this as $(this).
$("#trashbutton").click(function() {
$(this).parent().parent().remove();
})

jQuery to append content to div by id not working [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Im trying to append content from a json-encoded result of an AJAX call as follows:
$.each(results["data"], function(i, result){
$("#resultset").append = result["name"];
console.log(result["name"]);
});
When executing the code, console.log records the names of the data elements, but the div remains empty. Not sure why.
HTML:
<div id="resultset">
</div>
.append() is a function that you call, not a property that you assign a value to, so:
$("#resultset").append(result["name"]) ;
(Depending on what is actually in result["name"] you may also want to append some <br> elements, or wrap each result in a <p> element or something...)
Also you JS is trying to use the id "result_set" but in your html the id is "resultset" without the "_".
You've specified the id to be targeted in your JQuery as result_set, but the id in the html is resultset.
You need to make sure these match up exactly!

jQuery add html to original-title? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I've got a button which looks like this:
<a class="buttonS bDefault tipN" id="customerBasket" original-title="<ul class='shoppingBasket'></ul>" href="#"><span class="icos-cart3"></span></a>
Its a tooltip and I want to append list-items to the class shoppingBasket.
I've tried by doing the following:
$('.shoppingBasket ul').append(<li><span class=\'basketPic\'>Test</span><span class=\'basketName\'>Test123</span></li>);
But I get the error:
SyntaxError: Unexpected token '<'
Any ideas what I'm doing wrong here?
You forgot your quotes:
$('ul.shoppingBasket').append("<li><span class='basketPic'>Test</span><span class='basketName'>Test123</span></li>");
EDIT after getting more info:
You're wanting to update an attribute, which is more complicated than just appending something to a dom element. But, you should be able to do it. Try something like this:
$button_title = $('.buttonS').attr('original-title');
$('body').append('<div id="cart-holder" style="display:none;">' + $button_title + '</div>');
$('#cart-holder ul.shoppingBasket').append('<li><span class=\'basketPic\'>Test</span><span class=\'basketName\'>Test123</span></li>');
$('.buttonS').attr('original-title', $('#cart-holder').html());
$('#cart-holder').remove();
This will add a div to the body with the HTML in original-title, append your HTML to it, set the original-title to it, then remove the element it just made. You'll likely have to tweak it to get the effect you want.
Fiddle
Please note that the append() method accepts a string. And you should always add a string to its parameter. Otherwise it won't work for you and you'll get this error.
append("<li><span class='basketPic'>Test</span><span class='basketName'>Test123</span></li>")
This would do it. Otherwise, it won't work.

JQuery not hitting when using secondary class as selector [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
(Code below) Trying to get a hover effect on the text in a div. Using class selectors in JQuery and it's not hitting when I use $('.abc') but does work when I use $('#top-nav-1') - not sure why it can't be hit when I select it by the secondary class. I can go through and use all the ids, but I'd rather just use one class - after all, that's what they're for!
Thanks, in advance, for the input on this.
HTML:
<div id="top-nav-1" class-"container abc">The Text</div>
CSS:
.container {
color: black;
}
JQuery:
$('.abc').hover(function() {
$(this).css('color','red');
});
fiddle: http://jsfiddle.net/yB9Jq/
You have a typo: class=, not class- (= not -).
Also, jQuery's .hover() takes two functions as arguments:
.hover( handlerIn(eventObject), handlerOut(eventObject) )
So an example would be:
$('.abc').hover(
function() {
$(this).css('color','red');
},
function() {
$(this).css('color','');
}
);
Your fiddle, updated.
Your markup is incorrect. You need to have class="container abc" instead of class-"container abc"
<div id="top-nav-1" class="container abc">The Text</div>
http://jsfiddle.net/yB9Jq/1/

document.execCommand('bold',false,true) does not work with jquery on("click", function(){}) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to do rich text editing with javascript and jquery.
I want to create a button to embolden selected text in a content editable div. When I tried with the following code, I get the expected result.
<div contenteditable="true" style="height:100px;width:100px;border:1px solid; " class="editor"></div>
<button class='bold' onclick="document.execCommand('bold',false,true);">B</button>
However, when I used jquery to do the same thing, it was not working.
<div contenteditable="true" style="height:100px;width:100px;border:1px solid; " class="editor"></div>
<button class='bold'>B</button>
$(function(){
$("button.class").on("click",function(){
document.execCommand('bold',false,true);
})
})
Why isn't jquery working for my problem ?
$("button.class").on("click",function(){
Change this to
$("button.bold").on("click",function(){
This is you can do and I hope this will definitely work.
$('.bold').click(function(){});

Categories