Reputation: 1760
i have a file that gets its content from another file, i use JS to call a php file that gets information from a database and display it.
This works fine, but i want to be able to get hold of the information that has been displayed from the other file, i thought i could use $('.className').val();
but this always seens to return 'undefined'.
this is the JS code so far: index.php
$(document).ready(function()
{
$(".trade_window").load('signals.php?action=init');
console.log($('.market_name_1').val());
});
As i said the output of the init is just fine but getting hold of the value is the problem, this is the HTML that it generated by the php file :
<div class="market">
<h3 class="market_name_1">GBPUSD</h3>
<img src="images/buy.png">
<p class="market_data">
</p><p>BUY</p>
<p class="market_data">1.55605</p>
<p class="market_data">18:21:02</p>
</div>
I am currently learning the wonders of JS and JQuery so looking to learn from my mistakes. Any ideas on this one? I really think i'm just missing something silly but i can't but my finger on it.
Upvotes: 0
Views: 77
Reputation: 2005
As Zenith mentioned: use text()
to retrieve the value from the heading.
You might get undefined
even after using text()
if the data hasn't been loaded by the time the statement is executed. You can use the callback provided for the load() function.
$(document).ready(function()
{
$(".trade_window").load('signals.php?action=init', function() {
console.log($('.market_name_1').text());
});
});
Upvotes: 4
Reputation: 68596
Use jQuery's text()
method instead to get the value from inside:
console.log($('.market_name_1').text());
You may also want to use an on('load')
instead of document.ready
.
Upvotes: 3
Reputation: 148
Try accessing the the value you need inside the callback function specified for the jquery load()
method. There is a complete
method that can be called when the data from the server is retrieved.
Upvotes: 1