how to get only the first <p> </p> tag contents in asp.net c#?

Posted by Prabu_Spark under ASP.NET on 12/11/2013 | Points: 10 | Views : 1837 | Status : [Member] | Replies : 3
Hi sir,
I am getting the string like below, i need to get only the first <p> </p> tag contents. Kindly give me the solution for this problem.



Input:
********

<p>You should step up and use some of this amazing energy to take action -- the world needs what you've got! It's a really good day for some parties, startups and other fun things that just need some initiative.</p><p>More horoscopes! Check your , , , , , ...</p><p>Today's Free Sample Reading: </p><p></p>



Output:
**********

<p>You should step up and use some of this amazing energy to take action -- the world needs what you've got! It's a really good day for some parties, startups and other fun things that just need some initiative.</p>

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: vishalneeraj-24503 on: 12/11/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi give the id to first <p> element like <p id="paragraph1">abc</p>

and access like
var text = document.getElementById('paragraph1').innerHtml.

Here,paragraph1 is your 1st <p> id.
innerHtml will give you the inner text.

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saranpselvam on: 5/15/2014 [Member] Starter | Points: 25

Up
0
Down
give me more inputs

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 5/16/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
Here is the code.
var inputStr="<p>You should step up and use some of this amazing energy to take action -- the world needs what you've got! It's a really good day for some parties, startups and other fun things that just need some initiative.</p><p>More horoscopes! Check your , , , , , ...</p><p>Today's Free Sample Reading: </p><p></p>";
var divElem=document.createElement('div');
divElem.innerHTML=inputStr;
var outputStr=divElem.firstChild;
alert(outputStr);//YOUR Output

Please mark as answer if code gives your required output.

Thank you,
Govind

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response