-1

I have a jquery function which gets data from a json php mysql. And the results are appearing in textboxes

function renderDetails(wine) {
$('#Id').val(wine.id);
    $('#question').val(wine.question);
    $('#answer').val(wine.answer);
    $('#link').val(wine.link).html();
}

The textboxes in HTML are like this

<label>link:</label>
<input type="text" id="link" name="link"/> 

Instead of a text box I would like to bring the link to a div!

<p id="link">This is where the link should appear.</p>

How would you write the jquery in order to feed the DIV ???

4

5 回答 5

3
$("#link").html( wine.link );
于 2013-09-26T17:41:52.667 回答
2

Well, for starters, that's not a div. That's a p. But beyond that, you can simply use the .text() function to set the contents of any such element:

$('#link').text(wine.link);

Or, for HTML content:

$('#link').html(wine.link);
于 2013-09-26T17:42:11.283 回答
1

Try this:

$('#link').html(wine.link);
于 2013-09-26T17:42:15.927 回答
1

You can use

$("#link")..text()

$("#link")..html()

or

$("#link").append()

depending in what you want to do.

于 2013-09-26T17:43:31.443 回答
1

My dear friend you are putting the fetched data into the element which id is link. look into your code you will find that your input element also have the same id "link". Otherwise you are doing good. Remember your html page can't have more than one element per id. cheers.

于 2013-09-26T17:46:12.437 回答