0

so for example i have a brunch of pages create by easytab which looks like below in HTML

<div class="tab-page1 identify">//something</div>

<div class="tab-page2 identify">//something</div>

<div class="tab-page3 identify">//something</div>

<div class="tab-page4 identify">//something</div>

And I'd like to add something in to the contents so i created a function like below

$(".identify").html("123");

I know i can do something like to add something in the last child but i'd like to add 123 in every child how may i do it?

$(".identify:last-child").html("123");
0

4 Answers 4

1

And I'd like to add something in to the contents

but i'd like to add 123 in every child how may i do it?

You can use .html(function) to add new html to existing html content.

$(".identify").html(function(index, html) {
  return html + 123
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="tab-page1 identify">//something</div>

<div class="tab-page2 identify">//something</div>

<div class="tab-page3 identify">//something</div>

<div class="tab-page4 identify">//something</div>

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the .each function to iterate each found node and perform a function:

$(".identify").each(function(){
    $(this).html("123");
});

Example JSFiddle

4 Comments

i am using easyTab so this seem only works on the first page
Can you post a more complete example that demos this?
$(".identify").html("123"); has the same result, the .each() part is redundant.
@Steve "And I'd like to add something in to the contents"
0

You don't need a loop to achieve this.Check it

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script>
$(document).ready(function(){
    $("#btn").click(function(){
        $(".identify").html("123");
    });
});
</script>


<div class="tab-page1 identify">//something</div>

<div class="tab-page2 identify">//something</div>

<div class="tab-page3 identify">//something</div>

<div class="tab-page4 identify">//something</div>

<button id="btn">Do it</button>

</body>

Comments

0

use the append to add something to the existing content:

$(".identify").each(function(){
    $(this).append("123");
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.