2017-03-18 3 views
0

gibt es eine Möglichkeit, dass ich nur einen kleinen Teil eines Skripts wie dies kann sein:Fügen Sie nur einen kleinen Teil eines anderes Skripts mit Javascript

<?php 
$url = 'https://www.example.com'; 
$content = file_get_contents($url); 
$first_step = explode('<div class="HelloWorld">' , $content); 
$second_step = explode('</div class="HelloWorld">' , $first_step[1]); 

echo $second_step[0]; 

... Aber nur mit Javascript statt PHP?

Dank

+0

mit jquery.fn.html Methode $ ('.Hellwold') .html() –

Antwort

0

Ich denke, was Sie wollen, ist die Innerhtml des div bekommen helloworld.using jquery.fn.html statt.

console.log($(".HelloWorld").html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="HelloWorld"><span>foo</span>bar</div>

oder Sie können es mit DOM api direkt tun, das Htmlelement hat ein innerHTML Attribut:

console.log(document.querySelector(".HelloWorld").innerHTML);
<div class="HelloWorld"><span>foo</span>bar</div>

Verwandte Themen