0

How can I get vaule of HTML element via .load function via cross domain? The .load function works perfect, but I don't know how to rich value of single element?

HTML code from I want to get values:

<div class="temeratura">
<ul id="temperatura_lista">
    <li id="temp_Sypialnia" value="22.25">Temp. Sypialnia: 22.25</li>
    <li id="temp_MalyPokoj" value="19.75">Temp. Mały pokój: 19.75</li>
    <li id="temp_Salon" value="23.00">Temp. Salon: 23.00</li>
</ul>

My JS on other HTML page on other server (it works):

<script>
$( '#new-tempSypialnia' ).load( "http://some.address.com/index.html #temp_Sypialnia("value")" );
</script>
1
  • If I could use PHP then won't be a problem, but I can't. Is any solution to use js? Commented Aug 20, 2014 at 17:49

1 Answer 1

1

Note, value property may set 22.25 to 22 , see console at jsfiddle , where 22 returned by element.val() , element[0].value , and element.prop("value") . 22.25 returned by element.data("value") from html data-* attribute.

Try

html

<!-- added `data-value` attributes , 
     having same `value` as `value` attributes ,
     to maintain same `data-value` when processed 
-->
<div class="temeratura">
<ul id="temperatura_lista">
  <li id="temp_Sypialnia" data-value="22.25" value="22.25">Temp. Sypialnia: 22.25</li>
  <li id="temp_MalyPokoj" data-value="19.75" value="19.75">Temp. Mały pokój: 19.75</li>
  <li id="temp_Salon" data-value="23.00" value="23.00">Temp. Salon: 23.00</li>
</ul>

js

$("#new-tempSypialnia")
.load("http://some.address.com/index.html #temp_Sypialnia #temp_Sypialnia"
, function(data) {
      var val = $(data).find("#temp_Sypialnia");

      // console.log("`elem.data('value')`:", val.data("value")
      //            , "`elem.val()`:", val.val()
      //            , "`elem[0].value`:", val[0].value); 

      var result = val.data("value");          
      alert(result);
});

jsfiddle http://jsfiddle.net/guest271314/ckLv2eub/

See

.load() , at complete callback

How to handle floats and decimal separators with html5 input type number

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.