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 = "";
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 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>
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 2 years ago.
Improve this question
Good day,
I would like to ask how I can get the value from price. Neither of them has a unique id so it makes things hard for a noob like me. Any suggestions? Thanks.
<div class="modal">
<span class="name">$</span>
<span class="price">0.04</span>
<hr style="background: linear-gradient(to right, #ffc82d , #ffff73);">
<div class="weapon" style="background-image: url('assets/img/free_case_item.png');"></div>
</div>
You can do it with pure JavaScript using DOM manipulation.
Assuming you only have one element with the price class: document.getElementsByClassName("price").item(0).innerText.
Ideally you would give it an ID (e.g. price): document.getElementById("price").innerText
You can try with document.querySelector:
var price = document.querySelector("div.modal span.price").innerText
This matches the first <span class="price"> inside <div class="modal">.
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 years ago.
Improve this question
How can I change the attributes of using class name or id name (for example ".testing a") using javascript?
Edit. I worded the question the wrong way. What I mean is I want to change the css of the a class.
document.querySelector('.testing a').setAttribute('color','green');
Something like above but the above code is not working.
<div class="testing">
<a>1</a>
<a>2</a>
</div>
You can use querySelectorAll() to get all required elements and use forEach() to loop to through elements and change style.color of element
let elms = document.querySelectorAll('.testing a');
elms.forEach(e => e.style.color = "green")
<div class="testing">
<a>1</a>
<a>2</a>
</div>
Using jQuery
$('.testing a').css('color','green');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="testing">
<a>1</a>
<a>2</a>
</div>
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>
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/