19

I have a number of tables, which have nested tables. I using jQuery to hide some of the table cells as a number are empty or the contents irrelevant.

I use jQuery to hide all TD's and then jQuery to show them, for instance, if they contain a <P>.

Unfortunately some of the TD's don't contain anything but still need to be shown. The class the TD's are given is dynamic so I wont be able to code for them all (Sensibly) however they do all end 'Node'

I was wondering if its possible to do something like...

$(function() {
   $('TR .*Node').css('display','inline');
});
3
  • 1
    A bit unreleated, but what exactly does the $(function() {...}); bit mean? What's the difference between that and just writing the contents? Is it to do with scope? Commented Sep 2, 2009 at 16:04
  • So a shorthand for $(document).ready(), or $(window).load()? Commented Sep 2, 2009 at 16:10
  • Which one? $(document).ready(), or $(window).load()? Commented Sep 3, 2009 at 8:36

3 Answers 3

38

This will select any tds with Node somewhere in their class name.

$('td[class*=Node]').css('display','inline');

This will select any tds with Node at the end of their class name.

$('td[class$=Node]').css('display','inline');

Bear in mind that .show() does roughly the same thing as .css('display','inline');

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

2 Comments

Just a note: I've had some trouble with the $= version in Firefox recently. If you have the same problem considering designing your classes a little differently. Remember, you aren't limited to one class per element.
Which reminds me, 'td[class$=Node]' will not match <td class="123Node specialcell">, as the class text does not end in node
3

The [attribute$="value"] selector will let you match attributes that end with a particular value. Note that using show() instead of changing the CSS directly will retain the display characteristics of the element you are revealing. If you really want to force them to display inline, you can revert it back to the css method with display: inline

 $('td[class$="Node"]').show();

Comments

2
$(function() {
     $('td[class*=Node]').css('display','inline');
});

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.