Which loop do i need if i want to sth until there are no more childnodes within a div? [closed] - javascript

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
Whats the best "loop" if i want to move child nodes 1 by 1 from one div to others. At the end there are no more img's left in the div (#load), so i thought i can use
do { ... } while ($('#load img')!=0);
I sort the img elements into 3 div elements depending on the width of each div.
Which loop would be the best? And how?

You can use .each() of jquery for that
$('#load img').each(function (index) {
if(index==n)
{
//do something here
}
$(this).fadeOut();
});

Related

If statement based on what element is underneath [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
I have a dynamic troublesome website;
Wondering if I could write an if statement with jQuery or raw JS that would hide an element based on if another element is underneath it.
So something like; if an <h1> tag is directly beneath my div id, keep my div element present; all else display: none;
You can use not, has and first-child selector:
$('div:not(:has(>h1:first-child))').hide();
Demo: http://jsfiddle.net/c9emjotg/
You could use css to hide all the appropriate divs, then use jquery to show them if they contain an <h1>
$('h1').parent('.sometimesHeader').show();
.sometimesHeader {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="sometimesHeader">I don't have an h1</div>
<div class="sometimesHeader"><h1>H1 is here!</h1></div>

Loop over HTML class to add a different ID to each HTML element with a specific class [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
I am trying to loop through an HTML page to check HTML elements with class="details" and then each element will that class with get an ID added to it. Of course the ID will be different for every HTML element that has class="details". Below is what I started to code, but I realized that if I have 20 HTML elements with class="details" that there has to be a way to loop or write less code to do what I want. Any help will be greatly appreciated.
$('.details').eq(0).attr('id' , 'cLc');
$('.details').eq(1).attr('id' , 'bLt');
Something like this?
$('.details').each(function(idx) {
$(this).attr('id', 'id-' + idx);
});

how to show div using it's ID and change the visibility from none to block? [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
i need a javascript code that gets a hidden div by Id and changes the style from display:none; to display:block; .
HTML:
<div id="post-author" style="display:none;">by samuel</div>
every post in my site has that html code on beginning. how can i be able to print or show element by it's Id ? thanks !
<script>document.getElementById("post-author").style.display="block";</script>
This will do what you're after :) Just put that in the head of your site
This has been answered a million times before... but here you go:
document.getElementById('post-author').style.display = 'none';
and
document.getElementById('post-author').style.display = 'block';

How to trigger a JavaScript function after “Bootstrap: collapse plugin” transition is done [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
I use this method
$jq('#indexClassData').on('hidden', function () {
// Do something…
expandIndexClass();
})
It does not work. What am I missing?
You need to wait for the "hidden.bs.collapse" event, not "hidden".
Scroll down to "Events" here: http://getbootstrap.com/javascript/#collapse-usage
thank you but i use another method
// ahmed taha to fix issue of documet coolapse
$jq('#indexClassData').on('shown.bs.collapse', function () {
expandIndexClass()
})

Contents between tags to turn into title 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 8 years ago.
Improve this question
I have <a class="wishlist">TEXT</a>
i need <a class="wishlist" title="TEXT"></a>
I can use only JS.
As your selector is a class, I'd set the function up to handle the possibility of multiples.
$('.wishlist').each(function() {
$(this).attr( 'title', $(this).text() ).empty();
});
Don't forget to either place this code after your HTML, or wrap it in document.ready.
$('.wishlist').attr('title', $('.wishlist').text() );
$(".wishlist").attr("title", $(".wishlist").text()).text("");
That will set the title attribute to the current text, and afterwards unset the text.
try it again:
$('.wishlist').attr('attr','TEXT').html("");
document.getElementsByClassName('wishlist').title = 'TEXT'
document.getElementsByClassName('wishlist').innerHTML = ''

Categories

Resources