html - How to Get particular child node class name using javascript? -


i want particular child node(i.e. class name). how can this. code

    <div id="mess">                      <h1>bhashyam school</h1>                         <p>ac nagar main road, nellore <br/>ho, nellore - 524001  </p>                      <p class="tel">telephone: +(91)-9603444376 </p>                      <p class="email">email: <a href="mailto:info@citydeal.in">info@citydeal.in</a></p>                      <p class="web">website: <a href="http//citydeal.in" target="new">http//citydeal.in</a></p>                      <p class="description">hours of operation :                          monday, tuesday, wednesday, thursday, friday, saturday: 09:30 10:00 pm<br>                         sunday: closed , modes of payment :                          cash                      </p>  <form name="contactform" method="post" action="send.php" onsubmit="return getchilds();">                     <p>                         <input id="box" type="text" name="telephone" placeholder="enter mobile number"/>                          <input type="hidden" name="strtosend" id="strtosend"/>                         <button type="submit" class="button" value="submit">get sms</button>                     </p>                 </form>     </div>      <script type="text/javascript">         function getchilds()     {         var arr=document.getelementbyid('mess').childnodes, str='';         for(var i=0; i<arr.length; i++) {             if(arr[i].innerhtml!=undefined) {                 str+=" "+(arr[i].textcontent||arr[i].innertext);             }         }         document.getelementbyid("strtosend").value=str;         return true;     }     </script> 

in above javascript code want childnodes particular class names (ex:p class="tel", p class="email").

with jquery ?

.children(".yourclass") 

documentation

and as said in comments, without jquery :

.queryselectorall(".yourclass") 

documentation

and because i'm nicest person in world, here working jsfiddle .queryselectorall() :

http://jsfiddle.net/f8deq/

(in order see result, set hidden input text)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -