jQueryの.attr()を使って、クリックしたサムネイルにメイン画像を切り替える方法をご紹介します。 imgタグのsrc要素をjQueryの.attr()を使って書き換えます。商品紹介カタログサイト等で使えます。 サムネイルとメイン画像のCSSの記述 ※サムネイルエリア(.boxwrap .simg)とメイン画像エリア(.boxwrap .bimg)のCSS記述です。必要に応じて書き換えてください。 <style> body{ font-family:Verdana,"Hiragino Kaku Gothic Pro","ヒラギノ角ゴ Pro W6",Osaka,"MS Pゴシック",Arial,sans-serif; padding: 0; margin: 0; overflow-x: hidden; } ol, ul { list-style: none; margin: 0; p
![【.attr()】クリックしたサムネイルにメイン画像を切り替え|DAD UNION – エンジニア同盟](https://cdn-ak-scissors.b.st-hatena.com/image/square/c6bc76e097d59a4278a43742cd955d50dc3ab5cc/height=288;version=1;width=512/https%3A%2F%2Fdad-union.com%2Fwp-content%2Fuploads%2F2021%2F05%2Fcap20220623.jpg)