jquery - Strip span and put into input -


this should pretty simple - content h1 tag, strip span tag , put remaining input tag

i have html:

<div id="contentarea">     <h1><span>course</span>arrangementname<h1>     <input type="hidden" id="arr1form_arrangement" name="arr1form_arrangement"> </div> 

jquery

var eventname = $('#contentarea h1').html(); eventname.find("span").remove(); var eventnametrim = eventname.html(); //alert(eventnametrim); $( "input[name*='form_arrangement']" ).val( eventnametrim ); 

but nothing happens - alert empty. firebug tells me "eventname.find not function" it's jquery 1.9.0

can please telle me whats going on?

if desired output arrangementname problem first line, should be:

var eventname = $('#contentarea h1'); 

...because makes eventname jquery object, on can use .find() span , remove existing second line. though removes span element page completely, might want this:

var eventname = $('#contentarea h1').clone(); 

...so have working copy won't affect displayed on page.

the next problem have variable called eventnametrim refer on last line of code $eventnametrim. remove $ latter names match.

if you're trying output of coursearrangementname, i.e., ignore <span> , </span> tags keep text content, can this:

var eventname = $('#contentarea h1').text(); $( "input[name*='form_arrangement']" ).val( eventname ); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -