javascript - jQuery: how to match final parts of ids -


in order open popup content, have many tag anchors ids start "poc" poc1, poc2, poc3... @ same way, have same number of tag div ids start "pop" pop1, pop2, pop3... how can match them in jquery poc1 --> pop1 poc2 --> pop2 i'm writing like

jquery("a[id^='poc']").click(function() {     jquery('#pop1').bpopup(); }); 

but instead of "pop1" need correspondent pop according final value of poc. possible?

get specific number replacing string poc clicked element's id:

jquery("a[id^='poc']").click(function() {     var num = $(this).attr('id').replace('poc','');     jquery('#pop' + num).bpopup(); }); 

example

click on each of poc elements , respective pop element red

$('[id^=poc]').on('click', function() {    var num = $(this).attr('id').replace('poc','');    $('[id^=pop]').removeattr('style');    $('#pop' + num).css({'color':'red'});  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <span id="poc1">poc1</span>  <span id="poc2">poc2</span>  <span id="poc3">poc3</span>  <span id="pop1">pop1</span>  <span id="pop2">pop2</span>  <span id="pop3">pop3</span>


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -