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>
Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top