How convert items li into json? (JS) [closed] - javascript

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 3 months ago.
Improve this question
How convert items li:
<ul id='list'>
<li>city1</li>
<li>city2</li>
<li>city3</li>
<li>city4</li>
</ul>
'["city1","city2","city3","city4"]'

const list = document.getElementById("list"),
cities = Array.from(list.children).map(each => each.innerHTML),
citiesJSON = JSON.stringify(cities)
console.log(citiesJSON)
<ul id='list'>
<li>city1</li>
<li>city2</li>
<li>city3</li>
<li>city4</li>
</ul>

Related

how to render array of only urls in react 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 1 year ago.
Improve this question
I am making a web app which is getting data in the form of http url which are of images eg:
let array = ["https://zjcdn.mangafox.me/store/manga/31721/142.0/compressed/m000.jpgtoken=e7bf6b3b8fa25c218502b913a9c722ec374229d6&ttl=1633968000","https://zjcdn.mangafox.me/store/manga/31721/142.0/compressed/m001.jpg?token=3cd1bb77873151a1311e0f87d3cdd68100045326&ttl=1633968000", "https://zjcdn.mangafox.me/store/manga/31721/142.0/compressed/m002.jpg?token=74b31d27c19d32b1abb3db47eeb97a5cb4f381c7&ttl=1633968000","https://zjcdn.mangafox.me/store/manga/31721/142.0/compressed/m003.jpg?token=ff06277b89a5764deccae021411342de9947f130&ttl=1633968000","https://zjcdn.mangafox.me/store/manga/31721/142.0/compressed/m004.jpg?token=a5641dc8ed4d61de17793f94a45e69ab38f5fce3&ttl=1633968000","https://zjcdn.mangafox.me/store/manga/31721/142.0/compressed/m005.jpg?token=659f9f64adad8356006bc939365b492004bedc12&ttl=1633968000","https://zjcdn.mangafox.me/store/manga/31721/142.0/compressed/m006.jpg?token=46641b886d2eef796860c5d29e2959e4cb621945&ttl=1633968000","https://zjcdn.mangafox.me/store/manga/31721/142.0/compressed/m007.jpg?token=6c8ff51fd06f5a0171bde3e3bee2c68606985918&ttl=1633968000"]
and I want to render them on page I have used following code:
`{
arr.map(e=>{
return <img src={`${e}`} alt="" />
})
} `
and this:
arr.map(e=> (<img src={e} alt="" />))
but the problem is it is only rendering one image instead of rendering all images.
I think you have got some issues with your array as it would appear is has some format problems. Here is the fix
{
array.map((el,i )=> <img key={i} src={el} /> )
}

short jQuery solution for a javascript code [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
Need a jQuery solution of a JavaScript code and more shorter than it is.
Code:
if (event.target.parentElement.parentElement.parentElement.parentElement.getAttribute("class").include("newSearch"))
where event is coming from,
$(document).on('click', '#divCl > #lnkCl', function (event) {
JQuery version : 2.2.4
HTML Code:
<div class"newSearch">
<div>
<div>
<div>
<div id="divCl">
<div id="lnkCl">
</div>
</div>
</div>
</div>
</div>
</div>
This is not the exact code, as we have different use for the divs in between.
Maybe something like this.
$(document).on('click', '#divCl > #lnkCl', function(event) {
if ($(this).parents(".newSearch").length) {
// do your thing
}
});

replace HTML list with List added with 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 5 years ago.
Improve this question
my solution: https://jsfiddle.net/thecodesalim/dsvgdkks/2/
HTML:
<div id=leaderboard class="panel hidden">
<h1>Leaderboard</h1>
<ol id=top10>
<li>Jyn Erso</li>
<li>Mon Mothma</li>
<li class="me">Han Solo</li>
<li>Galen Erso</li>
<li>Thane Kyrell</li>
<li>Norra Wexley</li>
<li>Ciena Ree</li>
<li>Malakili</li>
<li>R5-D4</li>
</ol>
</div>
JS:
function updateLeaderBoard(arr,me){
let players = document.getElementById("top10");
for(let i =0; i < arr.length;i++){
let li = document.createElement("li");
li.appendChild(document.createTextNode(arr[i]));
players.append(li);
if(arr[i].includes(me)) li.classList.add("me");
}
}
updateLeaderBoard(["Jack","Robo","Simi"],"Robo");
I want the text content to be only the list in javascript, the html list should be replaced.
Thanks
I believe you are saying that the HTML list is a placeholder and you want to clear it out and just insert whatever you want from js? If so, just empty the <ol> when you have selected it:
let players = document.getElementById("top10");
players.innerHTML = "";

how to get the full html element using jquery? [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 want to get all full element using class
<div class="number">one</div>
<div class="address">addr1</div>
<div class="number">twod</div>
I want what are all the div having class name number, I want output full content with tags one by one using foreach statement. The expected output is like below
<div class="number">one</div>
<div class="number">two</div>
$('.number, .address').each(function() {
console.log(this.outerHTML)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="number">one</div>
<div class="address">addr1</div>
<div class="number">twod</div>

Change text in class with deferent text [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
Is it possible with jQuery to append a different word at the end of each node with a same class ?
For example:
<p class="xyz">Some text</p>
<p class="xyz">Some another text</p>
<p class="xyz">Text somewhere</p>
would then be:
<p class="xyz">Some text word1</p>
<p class="xyz">Some another text word2</p>
<p class="xyz">Text somewhere word3</p>
Thanks
Use:
$('.xyz').each(function(i){
$(this).html($(this).html()+" word"+(i+1));//or $(this).text($(this).text()+" word"+(i+1));
});
Working Demo
Look at this:
$('.xyz').each(function(i){
var count = i+1;
$(this).html($(this).html()+ "word" + count)
});
http://jsfiddle.net/y9043kdn/1/

Categories