是否可以使用函数编辑DIV标签ID名称?

I have a plugin that uses 3 completely identical divs on the page, using the same classes.

<div class="my-class"> <div class="my-class"> <div class="my-class">

I would like to edit the code of the plugin and add an id to each div, so I can work with it later using css.

But I don't want to touch the parent code due to the later update issues.

Is there a way to add the id tag to a div using just functions placed in functions.php file ??


Guys, also 1 additional question following the 1 above.

You have downvoted this question -2. I have recently received a message from administrator about my account restriction due to this. I don't think I asked a stupid question and I'm not a coder my self so maybe it was stupid, but obviously I'm just trying to understand why you didn't take it very well and what type of questions should I avoid in the future. Your comment would be really appreciated, specially the one who gave it a downvote. Cheers.

You can differ them using CSS, without need to add them ID attribute.

<div class="my-class"></div>
<div class="my-class"></div>
<div class="my-class"></div>

<style>
    .my-class {width: 200px; height: 100px; background: red;} /* rules for all .my-class elements, eg. width&height, whatever */
    .my-class:nth-child(2) {background: green}
    .my-class:nth-child(3) {background: blue}
</style>

http://jsfiddle.net/fwy38om7/

You can refer them using Jquery like

$(".my-class").each(function() {

})

Add below javascript to add id to your div

i=0;
$(".my-class").each(function() {
$(this).attr('id', 'constanttext' + i);
i++;
})