Clément Andraud
Clément Andraud

Reputation: 9269

Retrieve an element in a string with jQuery

I have a string in jQuery $(elm).parent().parent().html().

This string return :

    <input name="formpage" value="formulaire_test" type="hidden">
<input name="postOK" value="accuse.html" type="hidden">
<input name="postNOK" value="erreur.html" type="hidden">
<input name="mailFrom" value="-1,-1,-1" type="hidden">
<input name="mailToName" value="Nom" type="hidden">
<input name="mailTo" value="[email protected]" type="hidden">
<input name="mailSubject" value="Sujet" type="hidden">
<input value="name=mailText" type="hidden">
<div class="headerForm"><p>En tete</p></div>
<fieldset><legend>Nouveau</legend>
<div id="para0101" class="entry"><label for="id0101">sdf</label>
<input id="id0101" name="input0101" type="text"></div>
<div id="para0102" class="entry"><label for="id0102">sf</label>
<input id="id0102" name="input0102" type="text"></div>
<div id="para0103" class="entry"><label for="id0103">sfd</label>
<input id="id0103" name="input0103" type="text"></div></fieldset>
<div class="footer">pied form</div>
<div class="submit"><input value="annuler" type="reset">
<input value="envoyer" type="submit"></div>

How can i retrieve for example the value En tete in <div class="headerForm"> ??

Thanks !

Upvotes: 0

Views: 90

Answers (5)

Swarne27
Swarne27

Reputation: 5737

Try this way,

$(function () {
 var allHtml = $(elm).parent().parent().html();
 alert($(this).find('.headerForm p').html());
});

Upvotes: 0

anhtuannd
anhtuannd

Reputation: 963

var xml = $('elm').parent().parent().html();
var xmlDoc = $.parseXML( xml );
var $xml = $( xmlDoc );
var $hdrFrm = $xml.find( "div.headerForm");

Upvotes: 0

andyf
andyf

Reputation: 3340

Try this: $(elm).parent().parent().find('.headerForm').text();

Upvotes: 0

Philipp Siegfried
Philipp Siegfried

Reputation: 986

$(".headerForm p",$(elm).parent().parent()).text();

this should do the trick

Upvotes: 1

Adil
Adil

Reputation: 148110

You need jquery class selector to access required element and use text method of jquery to get its text.

requiredvalue = $('.headerForm').text();

Upvotes: 1

Related Questions