简体   繁体   中英

jquery get selector information and append to div not working

I want to get element that called the function and append embed Google map to target div. I'm trying with this code but not working

function myfunction(currentElement){

    var $elemId = $(this).attr("id");
    $( ".$elemId" ).append( "<iframe frameborder="0" scrolling="no" marginheight="0" 
    marginwidth="0" src="https://maps.google.ch/maps?f=q&amp;source=s_q&amp;hl=de&amp;geocode=&amp;q=Bern&amp;aq=&amp;
    sll=46.813187,8.22421&amp;sspn=3.379772,8.453979&amp;
    ie=UTF8&amp;hq=&amp;hnear=Bern&amp;t=m&amp;z=12&amp;
    ll=46.947922,7.444608&amp;output=embed&amp;iwloc=near"></iframe>");

}
<div class='Flexible-container'>
  <a href="#" id="showmap0" name="showmap0" onclick="myfunction(this);">show</a>
  <div class='showmap0'></div>
</div>

For Id we use #selectId

    function myfunction(currentElement){
     var $elemId = $(this).attr("id");
 $( '#'+$elemId ).append( "<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.ch/maps?f=q&amp;source=s_q&amp;hl=de&amp;geocode=&amp;q=Bern&amp;aq=&amp; sll=46.813187,8.22421&amp;sspn=3.379772,8.453979&amp; ie=UTF8&amp;hq=&amp;hnear=Bern&amp;t=m&amp;z=12&amp; ll=46.947922,7.444608&amp;output=embed&amp;iwloc=near"></iframe>" );
     }

I hope this help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM