Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
portlets: Updating portlet code
Adding elements: Killing off this section, this is a really bad method as portlets are much more complex than just a div. Just use the functions, please
Line 292:
'My logs', 'pt-mylogs');
</source>
 
=== Adding elements ===
In all other cases there are two ways to insert new elements:
 
1) adding them to <tt>'''innerHTML'''</tt> of the parent element
 
<source lang="javascript">
//Example: using innerHTML to create a new portlet
document.getElementById('p-tb').innerHTML +=
'</div>'+
'<div id=p-"mything" class="portlet">'+
'<h5>mine</h5>'+
'<div class="body"><ul>'+
'<li><a href="/wiki/Special:MyPage/vector.js">My vector.js</a></li>'+
'</ul></div>'+
'</div>';
</source>
 
 
2) using DOM methods: <tt>'''createElement()'''</tt>, then attach as child using <tt>'''appendChild()'''</tt> or <tt>'''insertBefore()'''</tt>. For examples of usage see the code of <tt>addPortletLink()</tt>
 
=== Removing elements ===