2

I have a table with some rows which are not normally displayed (using a class with CSS display:"none";). On a button press I want to display these rows. The problem is that the whole table is dynamically added to the page and so the code does not work.

HTML

<tr class="HiddenRowClass"> ....  </tr>

JS

function ShowRowsClick() {
$(".HiddenRowClass").css("display","");
}

I have read about using .on() for binding events to dynamically generated elements, but I can't find anything talking about non event binding. (If that is the correct term for it)

6
  • Remove css property display instead $(".cssClass").removeCss("display") Commented Oct 19, 2014 at 6:46
  • @Mihir are you sure? Commented Oct 19, 2014 at 6:48
  • @doniyor thanks. Please ignore my previous comment, method removeCss does not exist. show method would do. Commented Oct 19, 2014 at 6:55
  • @Mihir I'm thinking that $("tr").removeClass("HiddenRowClass"); would work. Commented Oct 19, 2014 at 6:57
  • 1
    @scartag probably not, this will remove identification class from the rows which are to be hidden Commented Oct 19, 2014 at 7:08

2 Answers 2

3

You'll have to make the display show.

$(".HiddenRowClass").css("display","block");

Alternatively since you hid it using "display:none" you can use a jquery function to reveal it.

$(".HiddenRowClass").show();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. This works a treat(.show()) . I often use display:none and then display:"" to hide and unhide things. I am not sure why it doesn't work in this case?
@DavidG display:"" doesn't work and in this case you had the display:none in a class so you needed the display:block to override the one in the HiddenRowClass
0

How are the rows dynamically added? And how are you binding the button click event to your ShowRowsClick () function? As long as the button is pressed after the rows are in the DOM, and you have an event binding the button click to your ShowRowsClick() function, you should be OK. If the rows are being added AFTER the button is clicked, then you will have to do something more complicated like having your button click function set a state variable and have your row-adding function check that variable to see if the rows should be displayed.

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.