To add CSS to dynamically generated elements have two options:
#1 - give this element a class and add the rules of that class to your CSS
So in PHP you add the newElement class
while ($row = mysql_fetch_array($query)) {
echo "
<table border=0 width=\"720\">
<tr id=\"div\" class=\"newElement\">
<td width=\"382\">
TEXTO
</td>
</tr>
</table><br><br>";
}
and in the CSS: .newElement{ opacity: 1;}
#2 - run the code you used above just after the elements were added, ie within the ajax onSuccess function
success: function (data) {
$("#esteID").css("opacity","1.0");
// ou então no elemento parente comum: $("#parente div").css("opacity","1.0");
}
Note: Ids must be unique. In your while
in PHP it looks like you’re using the same ID. This gives errors in the code, the most common rule is to be applied only to the first element that has the ID you want. If you want to use the same rules on multiple elements, then use class
. If you want to generate Ids dynamically within your while
can add a counter that adds an extra number to your ID. But to give you an exact example I need to know better how you use ajax.
EDIT:
After seeing your answer I realized that the wig was poorly made (now corrected) and that what you need is to use event delegation because Event Handler was run before html was on the page. So use it like this:
$(document).on('mouseenter', '.div', function () {
$(this).css("opacity", 1);
});
$(document).on('mouseleave', '.div', function () {
$(this).css("opacity", "0.8");
});
Never use the same id for more than one element , id's are unique
– Erlon Charles
Did you see my Dit on the answer about delegating events? tested this?
– Sergio