Nun, ich würde antworten, dass es nicht, aber ich bin keine richtige Antwort zu sehen (von meiner POV):
function addElement(tdId) { // Specify the id the of the TD as an argument
$('#' + tdId).append(// Append to the td you want
$('<a></a>').attr({ // Create an element and specify its attributes
'href': '/home',
'title': 'Home'
}).append(// Also append the image to the link
$('<img />').attr({ // Same, create the element and specify its attributes
'src': 'image.png',
'width': '100px',
'height': '100px'
})
) // Close the "append image"
) // Close the "append anchor"
}
Nun, da eine reine Antwort jQuery ist. Eine JavaScript-Antwort wäre folgende:
function addElement(tdId) { // Specify the id the of the TD as an argument
// Create the DOM elements
var a = document.createDocumentFragment('a'),
img = document.createDocumentFragment('img') // See the use of document fragments for performance
// Define the attributes of the anchor element
a.href = '/home'
a.title = 'Home'
// Define the attributes of the img element
img.src = 'image.png'
img.width = '100px'
img.height = '100px'
// Append the image to the anchor and the anchor to the td
document.getElementById(tdId).appendChild(a.appendChild(img))
}
Ich denke, die Js-Version ist lesbarer. Aber das ist nur meine Meinung; o).
Dies wird einfach durch Beratung die offizielle Dokumentation jQuery recherchiert. http://api.jquery.com/append/ – Patrick
Vergessen Sie nicht, die Antwort als akzeptiert zu markieren, wenn Sie die Informationen erhalten, die Sie wollen –