There is a code

"<div class='news-img-area'><center><a href='/upload/" . $img . "' data-rel='lightcase'><img src='/upload/" . $img . "'></a></center></div>"; 

How can you do this:

 if ($(window).width() < 701) { удалить a href из кода указанного выше (чтобы показывалась только картинка без перехода по ссылке) } 
  • if ($ (window) .width () <701) {$ (". news-img-area a"). removeAttr ("href"); } - ArtResh
  • one
    And you did not think to duplicate the markup - two containers side by side, in one picture + link, in the other - only picture, and the css-rule @media screen and (max-width: 700px) controls their visibility - either one or the second container will be hidden . Minus - a bit more code in the markup, plus - it makes the browser, not you) - Mi Ke Bu

2 answers 2

For example:

  if ($(window).width() < 701) { $('a').attr('href', ''); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class='news-img-area'> <center> <a href='/upload/" . $img . "' data-rel='lightcase'> <img src='/upload/" . $img . "'></a> </center> </div> 

Or so:

  if ($(window).width() < 701) { $('a').removeAttr('href'); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class='news-img-area'> <center> <a href='/upload/" . $img . "' data-rel='lightcase'> <img src='/upload/" . $img . "'></a> </center> </div> 

If you delete the entire link:

  if ($(window).width() < 701) { var wrap = $('.news-img-area'), link = wrap.find('a'), img = wrap.find('img'); img.appendTo(wrap); link.remove(); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class='news-img-area'> <center> <a href='/upload/" . $img . "' data-rel='lightcase'> <img src='/upload/" . $img . "'></a> </center> </div> 

  • I understand it is necessary not to delete the link, but the entire tag a , leaving the contents - Artem Gorlachev
  • @ArtemGorlachev, added this option))) - HamSter

 if ($(window).width() < 701) { $('a').replaceWith($('a').html()); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class='news-img-area'> <center> <a href='/upload/" . $img . "' data-rel='lightcase'> <img src='/upload/" . $img . "'> </a> </center> </div> 

  • Class, compact! - HamSter