javascript - Wrap div with first anchor in div -


i need wrap .wrapme divs first link inside each of them. have more 1 box , div has anchor if anchor href www.nnn.com go www.nnn.com when clicked div.

$(document).ready(function() {    $(".wrapme").each(function() {      var $a = $('a', this);    });  })
.historybox {    width: 300px;    padding: 10px;    background: rgba(0, 0, 0, .8);    color: #fff;    margin: 10px;  }    .historybox {    color: #fff;  }
<div class="historyform">      <div class="historybox wrapme">      <a href="http://www.google.com" class="historyname">name,surname,bla bla</a>        <span>17 news</span>    </div>        <div class="historybox wrapme">      <a href="http://www.youtube.com" class="historyname">employe id,employe name,adfhsd</a>        <span>22 news</span>    </div>    </div>    <!-- history -->    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

use wrapall wrap .wrapme divs inside anchor tag.

refer code:

$(document).ready(function() {    $(".wrapme").each(function() {      $(this).wrapall("<a href='"+ $(this).find("a").attr("href") +"' />")    });  })
.historybox {    width: 300px;    padding: 10px;    background: rgba(0, 0, 0, .8);    color: #fff;    margin: 10px;  }    .historybox {    color: #fff;  }
<div class="historyform">      <div class="historybox wrapme">      <a href="http://www.google.com" class="historyname">name,surname,bla bla</a>        <span>17 news</span>    </div>        <div class="historybox wrapme">      <a href="http://www.youtube.com" class="historyname">employe id,employe name,adfhsd</a>        <span>22 news</span>    </div>    </div>    <!-- history -->    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -