1

i have written a jquery that populates a html table from data that stored in a json array. in one of the fields, i want to create a hyperlink for it.

The table displays a list of files with the properties of filename, id, type, size and os.

i want the filename property to be a hyperlink of my choosing but i am not sure why its not working with the code below. if i remove the ("a").attr() and just leave it as default, it will display the filename coloumn but if i add that function in the code the filename column disappears.

here is the code below:

 <script src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script>
            var files = ${jsonArray}
            $(document).ready(function() {
                var table = $('<table border="1"/>').appendTo($('#somediv'));
                $(files).each(function(i, file) {
                    $('<tr/>').appendTo(table)
                        .append($('<td/>').text(file.FileObject.id))
                        .append($('<td/>').text( $("a").attr("file.FileObject.filename", "http://www.google.com/")   ))
                        .append($('<td/>').text(file.FileObject.type))
                        .append($('<td/>').text(file.FileObject.size))
                        .append($('<td/>').text(file.FileObject.os));
                });
            });
        </script>

3 Answers 3

2
$('<td/>').text( $("a").attr("file.FileObject.filename", "http://www.google.com/"))

should be

$('<td/>').html( $("<a>").text(file.FileObject.filename).attr("href", "http://www.google.com/"));
Sign up to request clarification or add additional context in comments.

Comments

0
.append($('<td/>').text( $("a").attr("href", "http://www.google.com/")   ))

Comments

0

have u tried using file.FileObject.filename instead of "file.FileObject.filename" i mean remove ur ""

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.