my first question. Also my english is far form being something I can describe as good, so please be forgiving (don’t know better word :)).
I am using php to generate table rows with diffrent style.
if ($n % 2 == 0)
$tr_class = ' class="package_' . $p->package_id . ' alt"';
else {
$tr_class = ' class="package_' . $p->package_id . '"';
}
<tr<?php echo $tr_class ?>
I want to select input field in fifth cell in each row that has class package_{number here} and add some styles to it.
To do so, I use that statement:
$('tr.package_' + package_errors_ids[i] + ' td:nth-child(5) input[type=text]').css('border', '1px solid red');
But second class (.alt) does not allow me to do this.
I don’t know how to modify that statement do achieve this.
Will you help? 🙂
I forgot to write it. It works but not everytime. Package_errors_ids is array containing numbers I use to create unique IDs for distinguish for user invalid packages. When 2 rows are invalid (one has .alt class), both are affected by this code css('border', '1px solid red');. But when one is valid, non of these rows are affected.
EDIT:
I’ve simplified my mixed js and php code in order to generate code without using JavaScript array
http://jsfiddle.net/TAdsT/7/
After this simplification and clearing my webbrowser cache, it works properly! Thank you all for your input. Here’s the code (if jsfindle.net erase it):
<script type="text/javascript">
$(document).ready(function() {
<?php
$count = count($this->package_errors_ids);
if ($count > 0)
{
for ($i = 0; $i < $count; $i++)
{
echo "$('tr.package_" .
(int) $this->package_errors_ids[$i] .
" td:nth-child(5) input[type=\"text\"]').css('border', '1px solid red');\n";
}
}
?>
});
</script>
I’m looking at this:
That will generate something like this, I assume:
That won’t have any problems at all in selecting a
<tr class="package_1 alt">. No trouble at all. Assuming your HTML is getting generated correctly, that means you’re doing something else wrong. And I’m going to assume that it’s this part:Try changing that to