c# - How could I find an element with similar ID in JS? -



c# - How could I find an element with similar ID in JS? -

in page have labels this:

contentplaceholder1_gvgroups_lblname_0

with corrosponding:

contentplaceholder1_gvgroups_lblhidden_0

i can assert *lblname has corrosponding *lblhidden.

now, have js:

//use create label 'edit' class editable function makelabelseditable() { $(".edit").focusout(function () { setlabel(this); }); $(".edit").click(function () { editlabel(this); }); } //used edit labels function editlabel(source) { source.innerhtml = '<input type="text" maxlength="40" value="' + source.innerhtml + '"/>'; $(source).unbind('click'); source.children[0].focus() } //used edit labels function setlabel(source) { if (source.children[0].value != '') { $(source).click(function () { editlabel(this); }); source.innerhtml = source.children[0].value; } }

i can assert marked class edit valid.

i need modify code so: //used edit labels

function setlabel(source) { if (source.children[0].value != '') { $(source).click(function () { editlabel(this); }); source.innerhtml = source.children[0].value; var hidden = somehowgethiddenfromsource(source); hidden.innerhtml = source.children[0].value; } }

i'm sure possible, not know how.

essentially, like:

getelementbyid(replace(source.id,'lblname','lblhidden'));

i not know js / jq functions can that.

thanks

essentially, like: getelementbyid(replace(source.id,'lblname','lblhidden'));

that's it. it's:

var hidden = document.getelementbyid(source.id.replace('lblname', 'lblhidden'));

hidden dom element.

or using jquery:

var hidden = $("#" + source.id.replace('lblname', 'lblhidden'));

hidden jquery instance wrapping element.

the id property of dom elements string. javascript strings have replace function accepts, in simple case, string replace , replacement string. (there's more that, that's need in case.)

c# javascript asp.net

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -