1

i am stuck here, actually wanted to change the href values of the a tag with rel=shadowbox property of a items in list , where the data is read from the table on the page.. here is my html code

   <div id="packgeImages">
        <ul>
<li class="title"><a href="" rel="shadowbox"><img src="../../images/packages2/agra1thumb.jpg" alt="thumb1" /></a></li>
    </ul>
    </div>

And here is my jquery code to capture the paths from grid and then append to the class .title

   <script type="text/javascript">
    $(document).ready(function () {
        var $title = $('.title').attr("href"); //Unable to capture this
        $('#fullImageGridView tr').each(function (i) {
            if (!this.rowIndex) return; // skips first row
            var bigSizeImagePath = this.cells[0].innerHTML;
          //  alert(bigSizeImagePath);
            $title.eq(i - 1).append(bigSizeImagePath);
        });
    });
</script>

I guess the appending is not working fine, the changes should be made linke this $("a").attr("href", "http://www.google.com/") I mean changing the attribute of href and not appending the values?? right?

3
  • can you check $('.title').length this will be helpful Commented Apr 16, 2013 at 3:34
  • 1
    It should be $('.title a').attr('href'). title is your li and a is inside title. Commented Apr 16, 2013 at 3:35
  • ok i did that and still not appended, and now the alert shows only first record, rest are skipped i guess.:( Commented Apr 16, 2013 at 4:25

3 Answers 3

2
var $title = $('.title a').attr("href"); 
Sign up to request clarification or add additional context in comments.

2 Comments

Looks like you're not targeting the a element
when i remove this line $title.eq(i - 1).append(bigSizeImagePath); the alert shows all the paths but when i add the line, it only reads the first one.??
2
$('[rel=shadowbox]').attr('href', yourValue)

Comments

0

modified code ::

<script type="text/javascript">
    $(document).ready(function () {
        var $title = $('.title [rel="shadowbox"]').attr("href"); //Unable to capture this
        $('#fullImageGridView tr').each(function (i) {
            if (!this.rowIndex) return; // skips first row
            var bigSizeImagePath = this.cells[0].innerHTML;
          //  alert(bigSizeImagePath);
            $title.eq(i - 1).append(bigSizeImagePath);
        });
    });
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.