paul y cho
paul y cho

Reputation: 39

How to get text from span ID

Under JQM, how can i get the text inside SPANs?

As i searched, there are hundreds of method to do that. But nothing available on my case.

I want display those SPAN value as 123 - 456 on section "mainPage".

<script>
$('a[name=submit_button]').click(function(){
 var Val1 = $('#zip1').text(text);
 var Val2 = $('#zip2').text(text);

 ...
</script>

<section id="mainPage" data-role="page">
 ...
</section>

<section id="zipSearch" data-role="dialog" data-theme="d">
 ...
 <ul><li><a name="sumit_button href="#mainPage"><span id="zip1">123</span><span id="zip2">456</span></li>
 </ul>
 ...
 </section>

Upvotes: 1

Views: 9104

Answers (2)

Bart Platak
Bart Platak

Reputation: 4465

Simply use

var Val1 = $("#zip1").text();
var Val2 = $("#zip2").text();

It probably doesn't work for you because you have syntax error in your a tag (forgot one of "). Change it to:

<a name="sumit_button" href="#mainPage">

EDIT: I have also just noticed you haven't closed your a tag either. Clear up your HTML tags, spooky things happen when you your strings or tags aren't terminated in the right place :)

Upvotes: 2

Daniel A. White
Daniel A. White

Reputation: 190907

I think you just want

var Val1 = $('#zip1').text();
var Val2 = $('#zip2').text();

Upvotes: 3

Related Questions