This question already has answers here:
How to Select Element That Does Not have Specific Class
(6 answers)
Closed 7 years ago.
I want to select all elements that don't have a specific class, how can I do this ?
I would like to have something like :
var test = document.getElementsByClassName(!"class");
Use
var test = document.querySelectorAll(":not(.class)");
But you'd better be a little more precise, for example targeting only divs:
var test = document.querySelectorAll("div:not(.class)");
Related
This question already has answers here:
How to get the value of an attribute in Javascript
(3 answers)
Closed 2 years ago.
I have this code:
<div id="progres-bar" class="progres-bar" value="90"></div>
I want to get value from this element where value="90", so the output should be 90 using javascript. I tried to make this with the below way:
document.getElementById("progres-bar").value;
but it didn't worked!
You can use getAttribute() function.
const value = document.getElementById("progres-bar").getAttribute("value");
console.log(value);
<div id="progres-bar" class="progres-bar" value="90"></div>
This question already has answers here:
Get next element with specific class of clicked element with pure js
(3 answers)
Closed 4 years ago.
Is it possible to search for the next sibling-element with a specified tag?
.nextElementSibling is not a function so... can't pass any tag with it?
jQuery
$(event.target).parent().next('div').attr('id')
Java Script
event.target.parentElement.nextElementSibling.getAttribute('id');
you should try using querySelectorAll https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll
and then simply just looping over the results for your desired result. Please have a look at the following js fiddle
https://jsfiddle.net/c0bdgxtj/12/
var wrapper = document.getElementById("wrapper");
var debugEle = document.getElementById("debug");
var desiredElements = wrapper.querySelectorAll('div[data-test="y"]');
This question already has answers here:
Replace method doesn't work
(4 answers)
Closed 6 years ago.
If I have a input box with value 'jklmnop', how would I go about removing 'k' using javascript?
I was thinking something along the lines of:
<input type='text' id='letters' value='jklmnop'/>
<button onclick='removeK()'>Remove</button
Using this javascript:
function removeK() {
document.getElementById('letters').value.replace('k','');
}
Can anyone tell me why this doesn't work? And if so, what would I need to do to make it work?
Thanks :)
You aren't setting the value.
var l = document.getElementById('letters');
l.value = l.value.replace('k','');
This question already has answers here:
jquery multiple attribute selector problem
(3 answers)
Closed 6 years ago.
I have these two conditions:
1) Find all div with a "data-filter-program" attribute which equal to something
2) Find all div with a "data-filter-expertise" attribute which equal to something
And I need to somehow combine these two into one statement in jquery. I would like something like this:
mentors = $("div").find("[data-filter-program*='"+selected_program+"']" && "[data-filter-expertise*='"+selected_expertise+"']");
How do I actually achieve this correctly in Jquery?
Thanks!
mentors = $("div").find("[data-filter-program*='"+selected_program+"'], [data-filter-expertise*='"+selected_expertise+"']");
Just add a comma between each item you would like to find.
$("div").find("#apples, #bananas, .grapes, div");
This question already has answers here:
How can I display a JavaScript object?
(40 answers)
Closed 7 years ago.
I have an array in javascript and I want to print/alert it (without change array).
my code is like this:
function myFunction() {
var fruits = [{'a':"Banana", 'c':"Orange", 'v':"Apple", 's':"Mango"}];
fruits[0].toString();
document.getElementById("demo").innerHTML = fruits;}
can anybody help me please?
You can simply use JSON.stringify:
JSON.stringify(fruits);
jsfiddle