reading content from a additionel file with div id
Hello,
I've twoo files. The first one is here.
- <!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Inhalte per Ajax nachladen</title>
<style type="text/css">
div {
border: 1px solid #ccc;
padding: 25px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
function kb_source_2_target() {
$.get('source.html', function(data) {
$('#target').html(data);
})
}
</script>
</head>
<body>
<h1>Inhalte per Ajax (jQuery) nachladen</h1>
<div id="target"> Die Inhalte in diesem Container werden nach dem Klick auf den Button mit den Inhalten aus der Datei <code>source.html</code> überschrieben. </div>
<p>
<button onclick="kb_source_2_target()">Hier klicken</button>
</p>
</body>
</html>
and the second here:
- Inhalte geladen! Rock n Rolli!
<div id="source">Halli hallo</div>
The jQuery should read the content in the second file and it works.
But now I will change my script in such a way that it only read the div id.
I've tried this here:
- <script>
function kb_source_2_target() {
$("#source").get('source.html', function(data) {
$('#target').html(data);
})
}
</script>