0

I have a <div> that is displayed and several <p> which are hidden inside that

<div class="em-booking-form-details">
<p class="ticket-price">
.........
.........
</div>

currently css is

.em-booking-form-details p{
    display:none;
}

i have a button register with id=register. when i click this button i want to be displayed all the <p> s . not that i cant use id for <p> and <div> and only use javascript.

2
  • But you can use jQuery for it or not? If so then $(document).on('click','#register',function() { $(".ticket-price").show() }); Commented May 10, 2014 at 6:38
  • 2
    He doesn't need jQuery Commented May 10, 2014 at 6:39

3 Answers 3

2

I provided a solution on jsFiddle http://jsfiddle.net/L5Xsg/

var dom_elements = document.querySelectorAll('.em-booking-form-details p');
var dom_length = dom_elements.length;

console.log(dom_elements);
for(var i = 0 ; i < dom_length ; i++) {
    dom_elements[i].style.display = 'block';
}
Sign up to request clarification or add additional context in comments.

Comments

2

document.querySelectorAll('.em-booking-form-details p')

Will return a list of DOM nodes that match that CSS selector. You can iterate over that list and set the display property to block or whatever you need

Comments

1
    var div = document.getElementsByClassName("em-booking-form-details")
    var p = div[0].getElementsByTagName('p')
    for(var i=0;i<p.length;i++){
            p[i].style.display = "block";       
    }   





    var p = document.getElementsByClassName('ticket-price')
    var all = p[0].parentElement.children
    for(var i=0;i<all.length;i++){
            all[i].style.display = "block";     
    }   

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.