For example, if I had 10 elements with the classes: “a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, respectively, what is the fastest way to change all 10 elements’ classes into different classes.
Category: javascript
Category Added in a WPeMatico Campaign
I want to know how to make the previous button appear only after the specific item was being shown in a carousel
I want to know if there is a way to have the prev button appear only when scroll value is equal to 200%(item2) or the next button was clicked once. I am new in coding, so I am not sure how to do it properly. There are currently 8 items.
How to apply active link in react
const location = useLocation();
const { pathname } = location;
const splitLocation = pathname.split("/");
const active = splitLocation[1] === item.path ? "sidebar-item active" : "sidebar-item";
so my problem is the “sidebar-item active” is not applying when click on a link.
How Do I Get the Selected Value from a Dropdown to Appear at the Top and Replace the Header?
I am using a dropdown for filters and want the selected value from the dropdown to appear at the top so users can see what their selection is when the dropdown closes and they continue browsing.
In this scenario, let’s say I select “Option 2”, I would want the span section value of “Category” to be replaced by “Option 2”. ( I tried using the HTML select and option tags but they just don’t work to trigger the filter.)
HTML
<div class="dropdown">
<span>Category</span>
<div class="dropdown-content">
<a href="www.site.com/option1"><p>Option 1</p></a>
<a href="www.site.com/option2"><p>Option 2</p></a>
<a href="www.site.com/option3"><p>Option 3</p></a>
</div>
</div>
CSS
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: fixed;
width: 50px;
padding: 4px;
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
p {
font-size: 16px;
}
}
Props.array change does not trigger useEffect
I am new to React and I am trying to update my list upon changes to the list using useEffect.
Background :
I have a list that creates buttons when the list is received from the server. So when the view is available, the list may not be available. So I have used useEffect to essentially listen to the changes in the list.
Here is my code snippet:
A.js
------
function A() {
this.list = [];
}
function onListUpdate(newList) {
console.log("Set list");
this.list = newList;
}
B.js
-----
export default function B (props) {
return (
<C a={props.a} />
);
}
B.props = {
a: PropTypes.object
}
C.js
-----
export default function C (props) {
const [list, setList] = React.useState([{...props.a.list}]);
useEffect(() => {
console.log("Called use effect");
setList(props.a.list);
}, [props.a]);
return (
<div>
{list.filter(l => l.view === true).map((l) => {
<Button imgSrc="icong.png" />
}
)}
</div>
);
}
C.props = {
a: PropTypes.object
}
So Set list log line gets printed when the list is recvd from server but the called use effect is not printed and neither are the button created.
Kindly let me know what needs to be done. TIA
Javascript keydown keypress
What I am trying to do is what is written in this readonly input
https://i.stack.imgur.com/L6jWI.jpg
will be also printed below it. This is my javascript code:
var input = $('#uom'),
label = $('#test');
input.bind('keydown keypress', function() {
setTimeout(function() {
label.text(input.val());
}, 0);
});
and this is my html code:
<input class="form-control" name="uom" id="uom" value="<?=$uom;?>">
<span id="test"></span>
Now it does work, when the input is not readonly whatever I type in the field it is working and everything is written below it. But the text that is written inside the input is coming from a button when it is pressed using jquery not a post, so when the text popup in the field there is no text below it, so I must click inside and press enter, I don’t want to do that, I need it automatically to be written, and also I need it readonly. How to do it ??
creating an object from an alphabetically sorted array where keys are the first letters and values are the strings
I’ve been trying to get an object output from an alphabetically sorted array.
For example, arr= [‘anger’, ‘apple’, ‘bowl’, ‘cat’]
then I want my object to be like obj = { a: [‘anger’, ‘apple’], b: [‘bowl’], c:[‘cat’]}
So far I have this, but it’s not working properly.
let val = {};
const sortArr = arr.sort();
for (let i = 0; i < sortArr.length; i++) {
for (let j = i; j < sortArr.length; j++) {
if (sortArr[i].charAt(0) == sortArr[j].charAt(0)) {
val.sortArr[j].charAt(0) =sortArr[j] ;
}
}
return val;
}
};```
Sending string message over WebSocket appears as blob object
I’m trying to make the beginning of a chat app, but whenever the client receives the message, it appears as a Blob Object
function init(){
if(ws){
ws.onerror = ws.onopen = ws.onclose = null;
ws.close();
}
ws = new WebSocket('ws://localhost:8080');
ws.onopen = () => {
console.log('Connection opened!')
}
ws.onmessage = ({ data }) => showMessage(data);
ws.onclose = function(){
ws = null;
}
}
sendBtn.onclick = function(){
if(!ws){
showMessage("No WebSocket connection!");
return;
}
ws.send(messageBox.value);
showMessage(messageBox.value);
}
init();})();
How to give a specified scope for interaction/Translate [closed]
Keep polygons within range
enter image description here
What is a difference while declaring a function between const functionName and function functionName? [duplicate]
As said in question title, what’s the real difference between const and function while declaring a function inside the module.exports ? For example:
const functionA = (value) => {
return 'real';
}
function functionB (value) {
return 'difference';
}
module.exports = { functionA, functionB }
Child element with height: auto inside heigthL 100vh parent
I have a layout, which allows me to have scroll appears on content-block with sticky dynamicaly sized header and footer. Wrapper height is set to 100vh to make it work, but when left or right column expands in its content, the height of the column stays the same as viewport height.
Fiddle – https://jsfiddle.net/vladllen/urd2g36w/3/.
<div class="wrapper">
<div class="header">
<button class="add-btn">Add</button>
</div>
<div class="content">
<div class="left">
<button class="add-btn">Add</button>
<h1>left</h1>
</div>
<div class="right">
<button class="add-btn">Add</button>
<p>right</p>
</div>
</div>
<div class="footer">
<button class="add-btn">Add</button>
</div>
</div>
.wrapper {
height: 100vh;
display: flex;
flex-direction: column;
overflow-y: hidden;
flex: 1;
}
.header {
background: red;
}
.footer {
background: blue;
}
.content {
flex: auto;
overflow-y: auto !important;
display: flex;
flex-direction: row;
}
.left {
background: yellow;
width: 70%;
}
.right {
width: 30%;
background-color: green;
}
When there is one column layout, there is no such problem. Fiddle – https://jsfiddle.net/vladllen/v6cw2q7a/1/.
<div class="wrapper">
<div class="header">
<button class="add-btn">Add</button>
</div>
<div class="content">
<button class="add-btn">Add</button>
<h1>title</h1>
</div>
<div class="footer">
<button class="add-btn">Add</button>
</div>
</div>
.wrapper {
height: 100vh;
display: flex;
flex-direction: column;
overflow-y: hidden;
flex: 1;
}
.header {
background: red;
}
.footer {
background: blue;
}
.content {
background: yellow;
flex: auto;
overflow-y: auto !important;
}
Is there any possible way to set children elements (.left and .right) to have height: auto (to have content heigh), when they are inside parent with 100vh, with pure css?
I could only think of javascript way, when dynamicaly calculate the content height and set heigth to this number.
Returning multiple PNG images for each mouse_click
I’m trying to return multiple PNG images for each mouse_click. I’ve set it up so that I can get multiple coordinates of a click, and then store those coordinates in a table. Then, loop the keys/values of the table to get each click. However, when I run the entire function it only produces the first page produced by splash.args.url, and does not include the clicks inside the loop. How can I integrate the clicks inside the loop effectively to produce multiple images?
function main(splash)
assert(splash:go(splash.args.url))
local get_dimensions = splash:jsfunc([[
function () {
var rect = document.querySelector('checkbox[number="1"]').getClientRects()[0];
var rect2 = document.querySelector('checkbox[number="2"]').getClientRects()[0];
return {"x": rect.left, "y": rect.top,
"x2": rect2.left, "y2": rect2.top}
}
]])
splash:set_viewport_full()
splash:wait(0.1)
local dimensions = get_dimensions()
local stuff = {[dimensions.x]=dimensions.y,
[dimensions.x2]=dimensions.y2}
for keys, values in ipairs(stuff) do
splash:mouse_click(keys, values) end
splash:wait(0.1)
return splash:png()
end
I can run each click successively, however how can I store the results of each click and return it?
How to push json data into an array using d3.json()?
I’m trying to insert the elements from this dataset:
https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json
into an array. But after the code, when I console.log(arr), the array is still empty.
The console.log inside the for actually works and prints the array, but arr.push doesnt. Why?
let url = "data.json";
var arr = [];
d3.json(url).then(data => {
for(let i = 0; i < data.data.length; i++) {
arr.push(data.data[i]);
console.log(data.data[i]);
}
})
console.log(arr);
<script src="https://d3js.org/d3.v6.min.js"></script>
Async cloudflare KV PUT request
I’m trying to use this fetch to then add some data into the KV on the .then how do I exactly structure this with the innermost function being async? At the moment I get the error Uncaught SyntaxError: Unexpected reserved word
This is the code:
fetch('https://www.uuidtools.com/api/generate/v4')
.then (data => {
await NAMESPACE.put(id, data)
})
is it possible to make certain API map markers appear, like in a if statement ??? I’d also appreciate if the user’s location can show up
I’m written a html, CSS, and JavaScript code
and I started writing the code and I have a map showing up with multiple markers but I want to have a set of marker appear only when a statement is true, and another set when another statement is true and so on.
also I’d like for it do show the user’s location and show them the how close they are from the closest marker.
thanks in advance, Sarah