AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



javascript-jquery: Format the paragraph with text and images in it

Hello
Help solve the task.
Add on the top button, and then 6 paragraphs with any text and images in them, one under the other. When you click on the button among all the images found for the odd, perform text extraction and assign this text to the corresponding lower/even paragraph and move the odd elements 40 pt to the left.

I know how to do part with text and it works, but how to do it with both text and images?


<button class="execute">Go!</button>

<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Optio, quos?</p>
<p>Lorem ipsum dolor sit amet.</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing.</p>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ducimus commodi vitae laborum itaque odio nihil dolores eveniet aut rerum eos!</p>
<p>Lorem, ipsum dolor.</p>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Consequatur, porro.</p>

var el = $("p");

$(".execute").click(function() {
el.each(function(i, value) {
if ((i + 1) % 2 == 1) {
$(this).css("padding-left", "40pt");
el[i + 1].innerText += ' ' + value.innerText;
}
});
});

javascript x 33
jquery x 12
Posted On : 2018-04-16 19:08:49.0
profile Aryan Gupta - anyforum.in Aryan Gupta
1900
up-rate
2
down-rate

Answers


Just use innerHTML in place of innerText. It will extract the whole HTML content no matter what it is(along with text) and push it to another element. please refer below line:

el[i + 1].innerHTML += ' ' + value.innerHTML;

Posted On : 2018-04-16 23:36:10
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188249980
Reply This Thread
up-rate
0
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in