Jquery Creating object from a Link and where to put the code

trevor1940 used Ask the Experts™

Have two Jquery questions

first is it possible to create a object from link to jpg's where the text on the link is image?
for instance

a link
<a href="myPic.jpg>Image 1</a>

jquery object

$("a > href > /image/i").each(function(){
      $(a")atrr("class", "fanceybox"     }

all other links add

$(a")atrr("target", "blank");

Then for links within a table how might i check that $(a")atrr("target", "blank"); hasn't been set or remove it if it has?

My second question is should the jquery script be within the head of the document or can you share the same script by creating a link the same as you would any other javascript eg

<script type="text/javascript" src="/js/my-jquery.js"></script>

i ask this because all the jquery scripts i've seen are either in the head or embeded within the document body.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Systems Manager
Top Expert 2012
second question is fairly easy. it can be anywhere, but make sure that the source of jQuery is before you try to use it. You should also surround all your manipulation in a $(document).ready().

The following script should add the class fanceybox to the anchor tags that have image in them in text and assign the target of blank to rest that aren't in tables:

<script type="text/javascript">
    if ($(this).text().match(/image/i)){
    }else if ($(this).parents("table").length===0){

Open in new window



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial