1
I need to manipulate an attribute of an html tag that was dynamically loaded via ajax. I have tried several ways using jQuery but none of them worked.
The code being loaded via ajax is as follows:
<table cellspacing="0" cellpadding="0" id="idTablePhoneFC" style="max-width: 480px;">
<tbody>
<tr>
<td class="EstChkValorCampo">
<input type="text" onchange="F$.fnCleanErrField('P2Telefone');" style="width:100px" maxlength="20" size="10" value="" id="P2Telefone" name="P2Telefone" class="InputText"><span></span>
</td>
</tr>
</tbody>
</table>
Note that the field input[type=text]
is with the attribute "style" forcing a maximum width of 100px.
I tried using CSS ! Important to try to force the element to be wider than this, but it is not accepting.
So my idea was to try using jquery, but I did not get results with the following code:
<script>
$(function() {
$("#P2Telefone").css('width','100%');
$(window).bind('load',function(){
$("#P2Telefone").css('width','100%');
});
$(window).load(function() {
$("#P2Telefone").css('width','100%');
});
$(window).on("load",function(){
$("#P2Telefone").css('width','100%');
});
});
</script>
Does anyone have any idea how to fix this?
Could you post how you are creating this dynamic html? If possible, also explain what you want to do with it.
– Randrade
I edited the question by putting code examples.
– robssanches
try to replace your . bind() method with the . delegate() or . on() method that is most current.
– Thomas Lima
OK Thomas Lima, thanks for the tip.. I’ll try and post the results.
– robssanches
I tried using the . on() method as directed by @Thomaslima but it didn’t work. The method . delegate() I don’t quite understand how I could apply it in this situation, as I need the css to be dynamically modified via jQuery as soon as the page loads.If anyone has any more ideas, please post.
– robssanches
Where do you have the function that loads the page dynamically? "$(window). load" refers to your current HTML and not your page that will be loaded.
– Filipe Moraes
@robsonds at the test level, try to change the '$(Function() {...}' to '$(Document). ready(Function((){...})
– Thomas Lima
@Filipemoraes the function that loads the content dynamically is at the end of the
<body>
. I’m not sure, but I think this is the function:<script>
F$.ShowWaitingFull();
function fnStartChk(){
 F$.CmdExecIn(F$.CmdChkRegister,{},F$.fnChkRegister);
}
window.onload=fnStartChk;
</script>
– robssanches
@Thomaslima altered
$(function() {...}
for$(document).ready(function(){...})
but it didn’t work unfortunately.– robssanches