Click here to Skip to main content
15,908,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there, i would like to get the value (string or int) which resides inside a

Element? for example:

HTML
<P id="AvailableSize">Select Size @item</P>


Where @item equals to a number '23' or maybe a string 'ten'?

What I have tried:

didn't tried anything so far as i am new to jquery and javascript, any help would be appreciated. Thanks in advance.

Posted
Updated 3-Mar-16 18:13pm
Comments
ZurdoDev 3-Mar-16 15:34pm    
In jquery do $("#idOfElement).val(). I believe that will work on a p as well.
Mohibur Rashid 3-Mar-16 17:13pm    
val() should work for input object and textarea
Mohibur Rashid 3-Mar-16 17:11pm    
Try $("#AvailableSize").html()

1 solution

As per your design try with below code:
HTML
<p id="AvailableSize">Select Size @item</p>

JavaScript
alert($("#AvailableSize").text().split(' ')[2]);

Although you will get @item value in above code, but it would be better if you use span inside p tag like:
HTML
<p id="AvailableSize">Select Size <span id="SizeCount">@item</span></p>

JavaScript
alert($("#SizeCount").text());
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900