在div中使用锚的href并将其应用于图像? [英] Take href of an anchor in a div and apply it to an image?

查看:34
本文介绍了在div中使用锚的href并将其应用于图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,其中包含图片和链接.

I have a div with an image and a link in it.

是否有可能在页面加载时以某种方式找到链接的href并应用图像的定位标记?

Is it possible that on page load, I can somehow find the href of the link and apply that the anchor tag of the image?

我知道这似乎是一个奇怪的请求,我问它是否可以完成,如果可以,怎么办?

I know this may seem like a strange request, i jsut asking if it can be done, and if so, how?

http://jsfiddle.net/fFgwb/

对不起,每个人,我想将图像包裹在锚标签中,并且与继续阅读"链接具有相同的href

Sorry everyone, I want the image to be wrapped in an anchor tag, witht he same href as the 'continue reading' link

推荐答案

仍然假设元素的位置,但基础知识如下. 非常非常简单,无需使用jQuery就可以在纯JS中完成此操作.

Still making assumptions about positioning of the elements, but the basics are below. Its very simple to do this in pure JS without needing to include jQuery.

实时演示

Live Demo

var link = document.querySelectorAll('.card-prod a');
link[0].href = link[1].href;

这篇关于在div中使用锚的href并将其应用于图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆