html - How can I implememt the following thing using Jquery and PHP -


suppose have 2 anchor tags , 2 divs there dynamic id. example:

<a id='a1' href="somepage">a1</a>& <a id='a2' href="somepage">a2</a> 

and

<div id='d1' >text1 </div> & <div id='d2' >text2 </div> 

initially, divs not displayed. when press a1 <a> tag div1 shown & when press a2 <a> tag div2 show , div1 not displayed.

how can implement using jquery , php?

the easiest way give <a> , <div> in common. way if have lot of div won't have repeat code on , on again

for example

<a href='#' class='showdiv' data-div='1'>a1</a> <a href='#' class='showdiv' data-div='2'>a2</a> <!-- data-div shows div button should show -->  <div class='hidden' id='box1'>one</div> <div class='hidden' id='box2'>two</div> 

and jquery

$('.showdiv').click(function(e){     //e.preventdefault(); //prevent # url or other default     var divid = $(this).data('div'); //get id number     $('.hidden').hide(); // hide div     $('#box'+divid).show(); //show 1 selected }); 

see in action


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -