/    Sign up×
Community /Pin to ProfileBookmark

Toggle bullet in table cell

Hello. I’m building a database of my music collection. I have a sortable table with five columns: artist, album, song, disc/track number, and playlist. On clicking a cell in the playlist column, I simply want to toggle between having a bullet in that cell and having it empty (for several reasons I don’t want checklists). The thing is that I don’t want to assign individual id’s to each cell. The only code I want is basically the following:
<td id=”playlist”><a href=”javascript:toggleBullet();”></a></td>.
I guess the javascript needs to know that the only cell to execute the function in is the one that is currently being clicked in. But how might I set this up? Thanks a lot.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 24.2003 — [font=monospace]<script type="text/javascript">

<!--

Array.prototype.next = function () {if (this.n == undefined || this.n >= this.length) this.n = 0; return this[this.n++]}

bullet = ['*', 'xa0']

// -->

</script>

<p>&nbsp;<span onclick="this.parentNode.firstChild.data = bullet.next()">toggle</span></p>[/font]
Copy linkTweet thisAlerts:
@fshea31authorAug 24.2003 — Thanks Charles, but that didn't do the trick. I'm using IE 5.5, so maybe that's part of the problem, but nothing's happening with that script.
Copy linkTweet thisAlerts:
@fshea31authorAug 24.2003 — I forgot to add that it mentions that this.parentNode.firstChild is not an object.
Copy linkTweet thisAlerts:
@FangAug 24.2003 — How about:
<i>
</i>function SwapContents(e) {
if(navigator.userAgent.indexOf("MSIE")!=-1) {
if(event.srcElement.tagName=="TD" &amp;&amp; event.srcElement.cellIndex==4) {
event.srcElement.innerHTML=(event.srcElement.innerHTML=="")? "&amp;#149;" : "";
}
}
else { <br/>
if (e.target == "[object HTMLTableCellElement]" &amp;&amp; e.target.cellIndex==4) {
e.target.innerHTML=(e.target.innerHTML=="")? "&amp;#149;" : "";
}
}
}

&lt;table onclick="SwapContents(event);" etc. &gt;
Copy linkTweet thisAlerts:
@fshea31authorAug 25.2003 — Thanks Fang. That worked perfectly. One more thing, if anyone has time: how about then clearing all the bullets with a button? Thanks dudes.
×

Success!

Help @fshea31 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...