In the Middle of a research. How do I unwrap the div with the ID #fromWhere
in the php script below. The I was able to do was addClass
. Whenever I try to wrap it, it unwraps almost every other element except itself. Any suggestions on how I can achieve this.
<?php ob_start(); ?>
<div id="fromWhere" >19977</div>
<?php $contents = ob_get_contents(); ?>
In my effort to unwrap it, I changed things over to make it look like below because it work when i tried targeting it from an external script.
<?php ob_start(); ?>
<script> $('#fromWhere').unwrap(); </script>
<div id="fromWhere" >19977</div>
<?php $contents = ob_get_contents(); ?>
Everything:
PHP
<?php ob_start(); ?>
<script> $('#fromWhere').unwrap(); </script>
<div id="fromWhere" > </div>
<?php $contents = ob_get_contents(); ?>
<?php
$params = array(
'origin' => $contents,
'destination' => um_user('postal_zip_code'),
'sensor' => 'true',
'units' => 'imperial'
);
$params_string='';
// Join parameters into URL string
foreach($params as $var => $val){
$params_string .= '&' . $var . '=' . urlencode($val);
}
// Request URL
$url = "http://maps.googleapis.com/maps/api/directions/json?".ltrim($params_string, '&');
// Make our API request
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
curl_close($curl);
// Parse the JSON response
$directions = json_decode($return);
//echo"<pre>";
//print_r($directions);
// Show the total distance
echo '<p><strong>Total distance:</strong> ' . $directions->routes[0]->legs[0]->distance->text . '</p>';
?>
<div id class="distance"></div>
jQuery that inserts the content into #fromWhere
$(document).ready(function() {
var from = $('#show-here #from').text();
$(".approved #fromWhere").text(from);
});