最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using jQuery to read img src and insert img src dynamically - Stack Overflow

programmeradmin0浏览0评论

I have some code on my page that looks like this:

<div class="img-center">
    <img src="img-path.jpg" alt="alt-text" class="feature-image" />
    </div>

I am setting up a Print Stylesheet and due to some javascript manipulation of the content (and possibly a bug in firefox) the img prints off center. The solution I am going to do is have the img inserted dynamically into another div that will show when printed but I do not know how to have jQuery read the img div and then copy it into the other div. The code example for the other div would be something like this:

<div id="feature-container-print">
   <img src="jQuery inserted copy of above img-path.jpg" alt="alt-text" />
     </div>

How is this done? Please provide an example.

I have some code on my page that looks like this:

<div class="img-center">
    <img src="img-path.jpg" alt="alt-text" class="feature-image" />
    </div>

I am setting up a Print Stylesheet and due to some javascript manipulation of the content (and possibly a bug in firefox) the img prints off center. The solution I am going to do is have the img inserted dynamically into another div that will show when printed but I do not know how to have jQuery read the img div and then copy it into the other div. The code example for the other div would be something like this:

<div id="feature-container-print">
   <img src="jQuery inserted copy of above img-path.jpg" alt="alt-text" />
     </div>

How is this done? Please provide an example.

Share Improve this question asked Jun 8, 2012 at 0:45 L84L84 46.3k59 gold badges181 silver badges259 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

$('#feature-container-print img').attr('src',$('.feature-image').attr('src'));

I believe this would work:

$('.feature-container-print img').attr('src', $('.img-center img').attr('src'));
$('.img-center img').hide();
$('.feature-container-print img').show();
发布评论

评论列表(0)

  1. 暂无评论