jquery prepend doesn't work in sharepoint 2013 forms
-
08-02-2021 - |
Question
I tried to add some label on Sharepoint 2013 forms with jquery prepend. I write a code for testing purpose, add a row with text 'Label1' before column name 'Project'. It doesn't work, 'Label1' is not showing up. See code below.
<script type="text/javascript" src="mysite/SiteAssets/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(doucument).ready(function(){
$('nobr:contains("Project")').closest('tr').prepend("<tr><td colspan='2'>label1</td></tr>");
});
</script>
La solution
You should use the below code.
<script type="text/javascript" src="mysite/SiteAssets/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(doucument).ready(function(){
$('nobr:contains("Project")').closest('tr').before("<tr><td colspan='2'>label1</td></tr>");
});
</script>
Append or prepending will put data INSIDE the caller elements. While After and before will create sibling elements. This might help you understand.
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange