views:

68

answers:

5

Hello,

I need some JQuery selector help...

My HTML is

<div id="Manager"><span>LastName, FirstName (UK)</span></div>

<span id=ctl00_PlaceHolderMain_g_4118aa1d_2690_4da8_b2b2_dc1943e73968_LineManager/>

I need to select the text from the div Manager and copy that into the span which contains the text LineManager.

I have the selector for the span which contains the text 'LineManager'

$("span[id*='LineManager']")

Thanks,

A: 

How about:

$("span[id*='LineManager']").html = $('#Manager span').html

Edit: Oops, it should have been

$("span[id*='LineManager']").html($('#Manager span').html)

as others have pointed out.

dvcolgan
It is totally wrong.
Sarfraz
looks good but doesnt seem to work...thanks, nav
nav
A: 
var span_text = $("div#Manager span");
$("span[id*='LineManager']").text(span_text);

I would recommend if possible, adding a non-dynamic class (for increased reliability) to the span element with the really long id. So your html ends up somenthing like this.

<div id="Manager"><span class="target-js">LastName, FirstName (UK)</span></div>    
<span class="fill-js" id="dynamicallyGeneratedString"/>

Then you can do a more maintainable:

var span_text = $("span.target-js");
$('span.fill-js').text(span_text);
Dr. Frankenstein
A: 

So maybe

var managerText = $("#Manager span").html();
$("span[id*='LineManager']").html(managerText);

Though the [id*=] attribute selector is not very efficient, so if you can figure out some other way of identifying your line manager you may see better performance. I typically like class based selectors for this, but I'm not sure if that is something you can add to your LineManager span or not.

ckramer
+1  A: 

I need to select the text from the div Manager and copy that into the span which contains the text LineManager.

This should do it:

$("span[id*='LineManager']").text($('#Manager').text());
Sarfraz
Spot on Thank you!
nav
A: 

JQuery:

    $(document).ready(function(){
        $("#button").click(function(){
            $("span[id*='LineManager']").html($("#Manager > span").html());
        }); 
    });

HTML:

    <div id="Manager"><span>LastName, FirstName (UK)</span></div>
    <span id="ctl00_PlaceHolderMain_g_4118aa1d_2690_4da8_b2b2_dc1943e73968_LineManager"></span>
    <input type="button" id="button">
Babiker